Re: How to upload a file with httplib?

Discussion in 'Python' started by John J. Lee, Jun 27, 2003.

  1. John J. Lee

    John J. Lee Guest

    "Hank Hu" <> 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
    John J. Lee, Jun 27, 2003
    #1
    1. Advertising

  2. John J. Lee

    hh Guest

    John,

    thanks a lot, I will try it.

    Hank Hu


    "John J. Lee" <> ???? news:...
    > "Hank Hu" <> 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
    hh, Jun 27, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FyYXY=?=

    Upload a file without file Upload control - ASP.Net

    =?Utf-8?B?U2FyYXY=?=, Aug 2, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,408
    Bruce Barker
    Aug 3, 2005
  2. Heather Fraser
    Replies:
    0
    Views:
    605
    Heather Fraser
    Jul 5, 2004
  3. alastair

    File upload using httplib

    alastair, Jul 26, 2004, in forum: Python
    Replies:
    3
    Views:
    8,249
    Jeff Shannon
    Jul 27, 2004
  4. Replies:
    1
    Views:
    902
    Gabriel Genellina
    Nov 25, 2006
  5. Prakash
    Replies:
    3
    Views:
    427
    Ray at
    Nov 12, 2003
Loading...

Share This Page