user1724641
user1724641

Reputation: 331

Python urllib2 gives error 503

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

Answers (1)

David Thomas
David Thomas

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

Related Questions