Skip to content Skip to sidebar Skip to footer

Urllib2 Gives Http Error 400: Bad Request For Certain Urls, Works For Others

I'm trying to do a simple HTTP get request with Python's urllib2 module. It works sometimes, but other times I get HTTP Error 400: Bad Request. I know it's not an issue with the

Solution 1:

You've got an extra colon in your headers.

headers = { 'User-Agent:': 'Mozilla/5.0' }

Should be:

headers = { 'User-Agent': 'Mozilla/5.0' }

Post a Comment for "Urllib2 Gives Http Error 400: Bad Request For Certain Urls, Works For Others"