python3: 'module' object is not callable - type is <class 'http.client.HTTPResponse'>

Chris Cioffi chris at evenprimes.com
Mon Dec 1 14:45:00 EST 2014


I'm writing a little script that uses a REST API and I'm having a problem using urllib in Python 3.

I had the basics working in Python 2.7, but for reasons I'm not clear on I decided to update to Python 3.  (I'm in the early phases, so this isn't production by any stretch.)


Python version info:
sys.version_info(major=3, minor=4, micro=2, releaselevel='final', serial=0)

Type() info of return object from urllib.request.urlopen:
<class 'http.client.HTTPResponse'>

Traceback of error when trying to pprint() the object:
Traceback (most recent call last):
  File "./test.py", line 59, in <module>
    testGetAvailableCash(lc)
  File "./test.py", line 12, in testGetAvailableCash
    print(lc.available_cash(INVESTORID, AUTHKEY))
  File "/Users/chris/dev/LendingClub/lendingclub.py", line 49, in available_cash
    return self._make_api_call(''.join((BASE_ACCOUNT_URL, investorID, "/availablecash")), authorizationKey)[u'availableCash']
  File "/Users/chris/dev/LendingClub/lendingclub.py", line 40, in _make_api_call
    pprint(lcresponse.read())
TypeError: 'module' object is not callable

The relevant code is as follows:
lcrequest = urllib.request.Request(url, data, {"Authorization": authorizationKey})
lcresponse = urllib.request.urlopen(lcrequest)

Any ideas on what I should be looking for?  Based on the docs and examples I would expect this to work. 

Thanks!

Chris




More information about the Python-list mailing list