[Tutor] urllib
Kent Johnson
kent37 at tds.net
Tue Sep 12 12:11:39 CEST 2006
Patricia wrote:
> Hi,
>
> I have used urllib and urllib2 to post data like the following:
>
> dict = {}
> dict['data'] = info
> dict['system'] = aname
>
> data = urllib.urlencode(dict)
> req = urllib2.Request(url)
>
> And to get the data, I emulated a web page with a submit button:
> s = "<html><body>"
> s += "<form action='a_method' method='POST'>"
> s += "<textarea cols='80' rows='200' name='data'></textarea>"
> s += "<input type='text' name='system'>"
> s += "<input type='submit' value='Submit'>"
> s += "</form></body></html>"
>
>
> I would like to know how to send a file. It's a text file that will be
> gzipped before being posted. I'm using python version 2.2.3.
There are some old examples hereA
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306
I think the modern way uses email.MIMEMultipart but I don't have an
example handy.
Kent
More information about the Tutor
mailing list