passing data to a liburl2 opener object

scriptlearner at scriptlearner at
Thu Jul 23 19:39:29 EDT 2009

I have prepared my headers and data for a HTTP POST message; however,
I am not sure how to pass the data to the opener.  Can you guys
provide some suggestions?  Thanks.

proxy_handler = urllib2.ProxyHandler({'http': '
opener = urllib2.build_opener(proxy_handler)

url = ""

headers['Content-Type'] = 'multipart/form-data; boundary=%s' %
headers['Cookie'] = 'somevalidcookiecontents'
#there is an opener.addheaders method for adding headers
data = multipart_encode(myDict)
#how to pass data to the opener???

With the codes above, I need to send out a HTTP POST like the
following one:

Content-Type: multipart/form-data;

Content-Disposition: form-data; name="picture"

PICTURE contents here
Content-Disposition: form-data; name="id"


More information about the Python-list mailing list