Simple httplib problem

Max M maxm at
Tue Jan 7 12:12:28 CET 2003

Afanasiy wrote:
> Can someone tell me what I am doing wrong here?

You are not using ClentCookie ;-)

With it you will be able to write code like the following, wich makes 
the process pretty painless (untested):

import urllib, urllib2, ClientCookie

class SiteBrowser:

     def __init__(self, url, **form_data):
         # form fields, including hidden ones
         data = urllib.urlencode(form_data)
         # login page
         request = urllib2.Request(url, data)
         result = ClientCookie.urlopen(request)
         self.content = ''

     def browse(self, url):
         # Find a password protected page
         req = urllib2.Request(url)
         res = ClientCookie.urlopen(req)
         self.content =

if __name__=='__main__':

     usr = 'user'
     pwd = 'secret'
     form_name = 'login_form', # hidden field!
     button = 'ok'
     url = ''

     browser = SiteBrowser(
             url, USERNAME=usr, PASSWORD=pwd, FORM_NAME=form_name, ok='')
     print browser.content


hilsen/regards Max M
Fremtiden, videnskab, skeptiscisme og transhumanisme

More information about the Python-list mailing list