Skip to main content

Author Topic: Lending Club API questions.

e
  • Posts: 2
Lending Club API questions.
OP: April 22, 2015, 11:00:00 PM
I have really confused about the new API. I am new guy for python, then I tried following


 req = urllib2.Request('https://api.lendingclub.com/api/investor/v1/accounts/111111/summary')  #111111 is my account ID
    try: response = urllib2.urlopen(req)
    except urllib2.URLError as e:
        print e.reason

But the code always failed with error code  "Unauthorized ".

what's wrong with the code.
  • IP logged

  • *****
  • Hero Member
  • Posts: 612
Lending Club API questions.
#1: April 22, 2015, 11:00:00 PM
You need an authentication header, as described here...

https://www.lendingclub.com/developers/authentication.action
  • IP logged

k
  • Posts: 29
Lending Club API questions.
#2: April 22, 2015, 11:00:00 PM
Since you are using python, I'd suggest using the "requests" module; install using "pip install requests".

Use a requests.Session instance, add the authorization header {''Authorization': 'your api key'} to the session header and then call the get method on the session instance with the url value.
  • IP logged

T
  • *****
  • Hero Member
  • Posts: 6586

T
  • *****
  • Hero Member
  • Posts: 6586

B
  • Posts: 26
Lending Club API questions.
#5: April 23, 2015, 11:00:00 PM
My C# code looks something like this.

Code: [Select]
  • IP logged

T
  • *****
  • Hero Member
  • Posts: 6586
Lending Club API questions.
#6: April 23, 2015, 11:00:00 PM
s = requests.Session()
s.headers.update({'Authorization':'zCdTrv+LoQ5w2J2Z5Y5BYRo22eM='})
r = s.get('https://api.lendingclub.com/api/investor/v1/accounts/910322/summary',auth=('heimlich22004@gmail.com','huahua1QA2WS3ED'))
    print(r.status_code)

I tried this, but the error code is 401. I cannot figure out the reason.
  • IP logged

T
  • *****
  • Hero Member
  • Posts: 6586
Lending Club API questions.
#7: April 23, 2015, 11:00:00 PM
With the authorization header added to the request Session instance, you do not need the "auth" parameter to be passed to the session instance's get method.  I "think", not sure, if you pass the auth parameter, it overrides the authorization header.

For your session instance, with no auth param, s.get(url) should work.  With the response instance from the session get call, the json() method will return your result.   :)
  • IP logged

j
  • Posts: 143
Lending Club API questions.
#8: April 23, 2015, 11:00:00 PM
I'd get a new auth code since you just gave everyone the code and your account number.
  • IP logged