i'm trying request restapi resource multiple times. in order save time, try use urllib3.httpsconnectionpool instead of urllib2. however, keeps throwing me following error:
traceback (most recent call last): file "lcrestapi.py", line 135, in <module> listedloansfast(version, key, showall='false') file "lcrestapi.py", line 55, in listedloansfast pool.urlopen('get',url+resource,headers={'authorization':key}) file "/library/python/2.7/site-packages/urllib3/connectionpool.py", line 515, in urlopen raise hostchangederror(self, url, retries) urllib3.exceptions.hostchangederror: httpsconnectionpool(host='https://api.lendingclub.com/api/investor/v1/loans/listing?showall=false', port=none): tried open foreign host url: https://api.lendingclub.com/api/investor/v1/loans/listing?showall=false
i'm using python-2.7.6
here's code:
manager = urllib3.poolmanager(1) url = 'https://api.lendingclub.com/api/investor/v1/loans/listing?showall=false' pool = urllib3.httpsconnectionpool(url+resource, maxsize=1, headers={'authorization':key}) r = pool.request('get',url+resource) print r.data
thanks help!
the problem you're creating poolmanager
never using it. instead, you're creating httpsconnectionpool
(which bound specific host) , using instead of poolmanager
. poolmanager
automatically manage httpsconnectionpool
objects on behalf, don't need worry it.
this should work:
# example called `manager` http = urllib3.poolmanager() url = 'https://api.lendingclub.com/api/investor/v1/loans/listing?showall=false' headers = {'authorization': key} # example did url+resource, let's assume url variable # contains combined absolute url. r = http.request('get', url, headers=headers) print r.data
you can specify size poolmanager
if you'd prefer, shouldn't need unless you're trying unusual limiting resources pool of threads.