Re: HTTP GET request with basic authorization?
From: Jonas Galvez (jonasgalvez_at_gmail.com)
Date: 01/03/05
- Next message: Alex Martelli: "Re: ? about file() and open()"
- Previous message: Alex Martelli: "Re: The Industry choice"
- Maybe in reply to: Christopher J. Bottaro: "HTTP GET request with basic authorization?"
- Next in thread: John J. Lee: "Re: HTTP GET request with basic authorization?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 2 Jan 2005 21:12:39 -0200 To: python-list@python.org
Christopher J. wrote:
> I tried this, but it didn't work:
> conn.request("GET", "/somepage.html", None,
> {"AUTHORIZATION": "Basic username:password"})
Hmm, try this:
import re, base64
userpass = base64.encodestring('user:pass').replace('\n', '')
authd = {'Authorization':'Basic %s' % userpass}
conn.request('GET', '/uri', None, authd)
Or this:
import re, base64, urllib2
userpass = ('user', 'pass')
url = 'http://somewhere'
request = urllib2.Request(url)
authstring = base64.encodestring('%s:%s' % userpass)
authstring = authstring.replace('\n', '')
request.add_header("Authorization", "Basic %s" % authstring)
content = urllib2.urlopen(request).read()
- Next message: Alex Martelli: "Re: ? about file() and open()"
- Previous message: Alex Martelli: "Re: The Industry choice"
- Maybe in reply to: Christopher J. Bottaro: "HTTP GET request with basic authorization?"
- Next in thread: John J. Lee: "Re: HTTP GET request with basic authorization?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]