通过其API

时间:2016-11-17 06:47:35

标签: python r curl lending-club-api

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

我正在使用python'request'模块进行调用,下面是我尝试过的代码:

    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 -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帐户 - &gt;刷新了身份验证密钥并执行了API调用,它开始工作。相当奇怪的方式来解决这个问题。

1 个答案:

答案 0 :(得分:1)

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

  1. 在R

    中使用httr

    库(HTTR) 结果&lt; - GET(&#34; https://api.lendingclub.com/api/investor/v1/loans/listing&#34;,           add_headers(.headers = c(&#34; Content-Type&#34; =&#34; application / json&#34;,&#34; Accept&#34; =&#34; application / json&#34;,                                    &#34;授权&#34; =&#34;验证密钥&#34;))) 输出&lt; - content(结果)

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

  3. 使用curl检查,与问题中的cURL实现相同。
  4. 但在完成所有这些操作之前,请确保您已通过浏览器登录Lending Club帐户。