Session

Manage the LendingClub user session and all raw HTTP calls to the LendingClub site. This will almost always be accessed through the API calls in lendingclub.LendingClub instead of directly.

class lendingclub.session.Session(email=None, password=None, logger=None)

Attributes

email  
last_response  

Methods

authenticate(email=None, password=None)

Authenticate with LendingClub and preserve the user session for future requests. This will raise an exception if the login appears to have failed, otherwise it returns True.

Since Lending Club doesn’t seem to have a login API, the code has to try to decide if the login worked or not by looking at the URL redirect and parsing the returned HTML for errors.

Parameters:

email : string

The email of a user on Lending Club

password : string

The user’s password, for authentication.

Returns:

boolean

True on success or throws an exception on failure.

Raises:

session.AuthenticationError

If authentication failed

session.NetworkError

If a network error occurred

base_url = 'https://www.lendingclub.com/'

The root URL that all paths are appended to

build_url(path)

Build a LendingClub URL from a URL path (without the domain).

Parameters:

path : string

The path part of the URL after the domain. i.e. https://www.lendingclub.com/<path>

clear_session_order()

Clears any existing order in the LendingClub.com user session.

get(path, query=None, redirects=True)

GET request wrapper for request()

head(path, query=None, data=None, redirects=True)

HEAD request wrapper for request()

is_site_available()

Returns true if we can access LendingClub.com This is also a simple test to see if there’s a network connection

Returns:

boolean

True or False

json_success(json)

Check the JSON response object for the success flag

Parameters:

json : dict

A dictionary representing a JSON object from lendingclub.com

last_request_time = 0

The timestamp of the last HTTP request

post(path, query=None, data=None, redirects=True)

POST request wrapper for request()

request(method, path, query=None, data=None, redirects=True)

Sends HTTP request to LendingClub.

Parameters:

method : {GET, POST, HEAD, DELETE}

The HTTP method to use: GET, POST, HEAD or DELETE

path : string

The path that will be appended to the domain defined in base_url.

query : dict

A dictionary of query string parameters

data : dict

A dictionary of POST data values

redirects : boolean

True to follow redirects, False to return the original response from the server.

Returns:

requests.Response

session_timeout = 10

Minutes until the session expires. The session will attempt to reauth before the next HTTP call after timeout.

set_logger(logger)

Have the Session class send debug logging to your python logging logger. Set to None stop the logging.

Parameters:

logger : Logger

The logger to send debug output to.

Exceptions

exception lendingclub.session.SessionError(value, origin=None)

Bases: exceptions.Exception

Base exception class for lendingclub.session

Parameters:

value : string

The error message

origin : Exception

The original exception, if this exception was caused by another.

exception lendingclub.session.AuthenticationError(value, origin=None)

Bases: lendingclub.session.SessionError

Authentication failed

exception lendingclub.session.NetworkError(value, origin=None)

Bases: lendingclub.session.SessionError

An error occurred while making an HTTP request