how can i pass through authrization box when i use urllib module?

Robert W. Bill rbill at digisprings.com
Wed Aug 16 16:56:42 EDT 2000


On Thu, 17 Aug 2000, Cho Yoonbae wildly tapped out:
> hi,
> 
> i'm making a client program which is update my dynamic ip to dns automatically.
> 
> i want to open such a web page.
> but it shows authrization box to me when i enter.
> 
> i am trying to solve this problem with urllib module.
> but, i couldn't find passing tools about authrization.
> 
> is there module or argument about that problem?

You just need to add an 'Authorization' header to send with
the request.

Below is a simple example with httplib that may point you in
the right direction:

import httplib
import base64

#make encoded Authorization string
username="choyoonbae"
passwd="LetMeIn"
authinfo = base64.encodestring(username + ":" + passwd)

h = httplib.HTTP('www.somesecretplace.com')
h.putrequest('GET', '/top/secret/document')
#put any needed headers here
h.putheader('Authorization', "Basic " + authinfo)
h.endheaders()
responsecode, responsemsg, headers = h.getreply()
#do what you want with responsecode, responsemsg, headers here
f = h.getfile()
data = f.read()
f.close()

print data


----------
Hope this helps.

-robert




More information about the Python-list mailing list