Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: How to upload a file with httplib? (http://www.velocityreviews.com/forums/t318913-re-how-to-upload-a-file-with-httplib.html)

John J. Lee 06-27-2003 01:07 PM

Re: How to upload a file with httplib?
 
"Hank Hu" <hankhu@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/Cli...-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

hh 06-27-2003 03:59 PM

Re: How to upload a file with httplib?
 
John,

thanks a lot, I will try it.

Hank Hu
hankhu2001@hotmail.com

"John J. Lee" <jjl@pobox.com> ???? news:87smpvk6sc.fsf@pobox.com...
> "Hank Hu" <hankhu@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/Cli...-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





All times are GMT. The time now is 10:22 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.