gpt4 book ai didi

python - 通过他们的 API 访问 Lending Club Loan 列表

转载 作者:行者123 更新时间:2023-11-28 18:27:05 25 4
gpt4 key购买 nike

我正在尝试通过此处提供的官方 API 从 Lending Club 获取贷款 list :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 帐户 --> 刷新了身份验证 key 并进行了 API 调用,它开始工作了。不过,解决这个问题的方式很奇怪。

最佳答案

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

  1. 在 R 中使用 httr

    图书馆(httr)结果 <- GET("https://api.lendingclub.com/api/investor/v1/loans/listing ", add_headers(.headers = c("Content-Type"="application/json","Accept"="application/json", "授权"="身份验证 key ")))输出<-内容(结果)

  2. 使用请求,与问题中的类似。

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

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

关于python - 通过他们的 API 访问 Lending Club Loan 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40648365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com