How to upload a file with httplib?

hh hankhu at 263.net
Fri Jun 27 11:59:48 EDT 2003


John,

    thanks a lot, I will try it.

Hank Hu
hankhu2001 at hotmail.com

"John J. Lee" <jjl at pobox.com> ???? news:87smpvk6sc.fsf at pobox.com...
> "Hank Hu" <hankhu at 263.net> writes:
>
> > I'm writing a prototype with python and need upload a zip file to a web
> > server. Any idea?
>
> http://wwwsearch.sourceforge.net/ClientForm/
>
> At your own risk, since file upload is poorly tested ATM.  You'd need
> this version:
>
> http://wwwsearch.sourceforge.net/ClientForm/src/ClientForm-0.1.3a.tar.gz
>
> IIRC, there's not yet a method on HTMLForm, so you need to use the
> control directly:
>
> import urllib2
> from ClientForm import ParseResponse
>
> forms = ParseResponse(urllib2.urlopen("http://www.example.com/"))
> form = forms[0]
> ctrl = form.find_control(type="file")
> # note multi-file upload not implemented yet
> # name and content_type args. to add_file are optional
> ctrl.add_file(open("my.zip"), name="my.zip")
> response2 = urllib.urlopen(form.click())
>
>
> John






More information about the Python-list mailing list