通过API访问贷款俱乐部贷款列表

2024-07-03 07:46:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图通过Lending Club提供的官方API获取贷款列表:https://www.lendingclub.com/developers/listed-loans.action

我正在使用python“requests”模块进行调用,下面是我尝试的代码:

    import requests
    header = {'Authorization' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type': 'application/json', 'Accept': 'application/json', "X-LC-LISTING-VERSION":"1.1"}
    resp = requests.get("https://api.lendingclub.com/api/investor/v1/loans/listing", headers= header, params = {'showAll':'true'})

得到回应:

^{pr2}$

我在这里通过stackoverflow问题中提到的R httr包尝试了这个解决方案:Lending Club API with R,但是得到了相同的401未授权响应。在

还做了一个快速卷曲检查我是否做错了什么。在

    curl -v -i --header "Authorization:xxxxxxxxxxxxxxxxxxxxxxxxxxxx" --header "Accept:application/json" --header "Content-Type:application/json" --header "X-LC-LISTING-VERSION:1.1" -d "{"query": {"showAll": "true"}}" -XGET https://api.lendingclub.com/api/investor/v1/loans/listing

以下是我得到的垃圾:

    *   Trying 64.48.1.18...
    * Connected to api.lendingclub.com (64.48.1.18) port 443 (#0)
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 1/3)
    * schannel: checking server certificate revocation
    * schannel: sending initial handshake data: sending 200 bytes...
    * schannel: sent initial handshake data: sent 200 bytes
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: failed to receive handshake, need more data
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 4096 length 4096
    * schannel: encrypted data length: 4006
    * schannel: encrypted data buffer: offset 4006 length 4096
    * schannel: received incomplete message, need more data
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 5030 length 5030
    * schannel: encrypted data length: 247
    * schannel: encrypted data buffer: offset 247 length 5030
    * schannel: received incomplete message, need more data
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 541 length 5030
    * schannel: sending next handshake data: sending 190 bytes...
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 6 length 5030
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 45 length 5030
    * schannel: SSL/TLS handshake complete
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 3/3)
    * schannel: incremented credential handle refcount = 1
    * schannel: stored credential handle in session cache
    > GET /api/investor/v1/loans/listing HTTP/1.1
    > Host: api.lendingclub.com
    > User-Agent: curl/7.45.0
    > Authorization:xxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > Accept:application/json
    > Content-Type:application/json
    > X-LC-LISTING-VERSION:1.1
    > Content-Length: 24
    >
    * upload completely sent off: 24 out of 24 bytes
    * schannel: client wants to read 16384 bytes
    * schannel: encdata_buffer resized 17408
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 141
    * schannel: encrypted data buffer: offset 141 length 17408
    * schannel: decrypted data length: 112
    * schannel: decrypted data added: 112
    * schannel: decrypted data cached: offset 112 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 112 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 112
    * schannel: decrypted data buffer: offset 0 length 16384
    < HTTP/1.1 401 Unauthorized
    HTTP/1.1 401 Unauthorized
    < Server: Apache-Coyote/1.1
    Server: Apache-Coyote/1.1
    < Content-Length: 0
    Content-Length: 0
    < Date: Thu, 17 Nov 2016 06:38:15 GMT
    Date: Thu, 17 Nov 2016 06:38:15 GMT
    <
    * Connection #0 to host api.lendingclub.com left intact

似乎我在API调用中遗漏了一些东西,或者在lound Club API中没有正确地记录。在

如果我能得到关于如何解决这个问题的建议那就太好了。在

谢谢!在

编辑:

我不知道发生了什么,但我登录了Lending Club帐户-->;刷新了身份验证密钥并进行了API调用,它开始工作了。不过,解决这个问题的方法很奇怪。在


Tags: comapissldataportbufferstepwith
1条回答
网友
1楼 · 发布于 2024-07-03 07:46:38

如果有人想试一试,我们可以使用以下方法:

  1. 在R中使用httr

    图书馆(httr) result<;-GET(“https://api.lendingclub.com/api/investor/v1/loans/listing”, 添加\u头文件(.headers=c(“Content Type”=“application/json”,“Accept”=“应用程序/json”, “Authorization”=“认证密钥”)) 输出<;-内容(结果)

  2. 使用请求,类似于问题。

  3. 使用curl进行检查,与问题中的curl实现相同。在

但在做这些之前,请确保您已通过浏览器登录到您的贷款俱乐部帐户。在

相关问题 更多 >