Reputation: 331
I m trying to run the following simple code:
import urllib2
import base64
username = "some_user"
password = "some_pass"
url = "some_url"
req = urllib2.Request(url)
authheader = "Basic %s" % base64.encodestring('%s:%s' % (username, password))
req.add_header("Authorization", authheader)
req.add_header('User-agent', 'Mozilla/5.0')
resp = urllib2.urlopen(req)
print resp.read()
It works fine on windows, but on the same machine under Linux it doesnt work, it gives URL exception with code 503. I m sure there is no problem with the server, because it works fine with Mozzila and curl (both under lin and win). What can cause this problem?
Upvotes: 1
Views: 2720
Reputation: 11
I was having a similar issue and eventually found that I had an environment variable "http_proxy" actually pointing at a proxy server. My problem went away when I either deleted the environment variable or explicitly set it to nothing in my Python script.
Upvotes: 1