3

我正在尝试通过此处提供的官方 API 从 Lending Club 获取贷款清单: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'})

得到回应:

    resp.status_code
    401

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

还做了一个快速的 cURL 来检查我是否做错了什么。

    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 调用中遗漏了一些东西,或者在 Lending Club API 中没有正确记录一些东西。

如果我能获得有关如何解决此问题的指示,那就太好了。

谢谢!

编辑:

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

4

1 回答 1

1

以防万一有人想尝试,我们可以使用以下方法:

  1. 在 R 中使用 httr

    library(httr) 结果 <- GET(" https://api.lendingclub.com/api/investor/v1/loans/listing ", add_headers(.headers = c("Content-Type"="application/json", "Accept"="application/json", "Authorization"="Authentication key"))) 输出 <- content(result)

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

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

但在执行所有这些操作之前,请确保您已通过浏览器登录到您的 Lending Club 帐户。

于 2016-11-19T15:50:28.973 回答