passing data to a liburl2 opener object

scriptlearner at gmail.com scriptlearner at gmail.com
Fri Jul 24 01:39:29 CEST 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': 'http://my.proxy.com:
3128/'})
opener = urllib2.build_opener(proxy_handler)

url = "http://sample.company.com:9999/service?"

headers['Content-Type'] = 'multipart/form-data; boundary=%s' %
myBoundar
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:

POST http://sample.company.com:9999/service?
Content-Type: multipart/form-data;
boundary=---------------------------1234

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

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

whateverid
---------------------------1234--



More information about the Python-list mailing list