Re: Django HTTP Basic Auth

91 views
Skip to first unread message

Aaron C. de Bruyn

unread,
Oct 18, 2012, 10:44:07 PM10/18/12
to django...@googlegroups.com
On Thu, Oct 18, 2012 at 6:55 PM, django <mait...@gmail.com> wrote:
I am trying to create a Django app, one of the thing I do in that is write a connection.py which connects to  a remote server. In that connection string I need to send one of the parameter as "http_auth = http_auth.HTTPBasicAuth(user, password)". I am not sure how to do that in Django. I searched the web a lot and nothing I got which is very relevant to what I am doing. Can anyone please help me. 

If I understand you correctly, you want to connect to a service that uses HTTP Basic Auth in connection.py and do something with the data.

You might look into python's urllib2 library.

I found this snippet:

import urllib2, base64

request
= urllib2.Request("http://api.foursquare.com/v1/user")
base64string
= base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request
.add_header("Authorization", "Basic %s" % base64string)  
result
= urllib2.urlopen(request)
Here:


-A

Matt Schinckel

unread,
Oct 18, 2012, 11:35:31 PM10/18/12
to django...@googlegroups.com
You may want to look into requests, which wraps http request-response handling in a nicer wrapper.


Matt.
Reply all
Reply to author
Forward
0 new messages