Passing a Cookie with httplib

scott at bogusaddress.com scott at bogusaddress.com
Wed Jun 28 16:08:49 EDT 2006


Hello,

>From a shell script, I have used /usr/bin/curl to access a web site
and pass a cookie (as required by the site). But, I can't seem to
accomplish this task with Python.  I would like to use the httplib
module to do this.  Any thoughts on this subject?  I would like to
hard code the cookie in the code so it works every time:   

i.e. cookie = 'auth=buster%3A12345678901234567890exZ9rzMqgtxa5A'.  

The question is - how do I pass it with httplib?  Here is what I have
so far:


# Import external modules
import sys
import httplib

# Define our site and path
WP_SERVER="www.foo.com"
WP_PATH='/somedir/confirmquery?value=%s' 
try:
    # Grab the command line argument
    uservalue = sys.argv[1]
    # Use the httplib module and connect
    conn=httplib.HTTPConnection(WP_SERVER)
    conn.request('GET',WP_PATH % uservalue)    
    response=conn.getresponse()
    data=response.read()
    conn.close()
    print data
except:
    print "Some stupid error occurred"
    sys.exit(1)


Any help would be greatly appreciated,

Scott



More information about the Python-list mailing list