Unable to fetch pdf with urllib2 : HTTP Error 400: Bad Request

We found that when trying to access, view, download files using urllib2 we occasionally came across the following error (<class ‘urllib2.HTTPError’>: HTTP Error 400: Bad Request)

In most cases when this happened we were able to access the files using httplib instead.

for example

instead of using urllib2.urlopen(geturl).read()

We would use

>>>conn = httplib.HTTPConnection(“serverAnd:portToAccess”)
>>> this = conn.putrequest(“GET”, “fileUrlGoesHere”)
>>> conn.endheaders()
>>> r = conn.getresponse()

Advertisements

2 thoughts on “Unable to fetch pdf with urllib2 : HTTP Error 400: Bad Request

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s