FAQ
I am trying to post file from python to php using HTTP POST method. I tried
mechanize but not able to pass the file object.

from mechanize import Browser
br=Browser()
response=br.open("http://localhost/test.php")
br.select_form('form1')
br['uploadedfile']=open("C:/Documents and
Settings/user/Desktop/Today/newurl-ideas.txt")
response=br.submit()
print response.read()

But, i get the error:
br['uploadedfile']=open("C:/Documents and
Settings/user/Desktop/Today/newurl
-ideas.txt")
File
"C:\Python25\lib\site-packages\clientform-0.2.9-py2.5.egg\ClientForm.py",
line 2880, in __setitem__
ValueError: value attribute is readonly

But,
When uploading is done using browser, it works.
--
Yours,
S.Selvam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081202/506ad5b7/attachment.htm>

Search Discussions

  • S.Selvam Siva at Dec 2, 2008 at 8:40 am
    I myself have found the solution.

    Instead of:
    br[br['uploadedfile']=open("C:/
    Documents and Settings/user/Desktop/Today/newurl-ideas.txt")

    We Need to use:
    br.add_file(open("C:/
    Documents and Settings/user/Desktop/Today/newurl-ideas.txt"),
    filename="newurl-ideas.txt",name="uploadedfile")
    On Tue, Dec 2, 2008 at 1:33 PM, S.Selvam Siva wrote:

    I am trying to post file from python to php using HTTP POST method. I tried
    mechanize but not able to pass the file object.

    from mechanize import Browser
    br=Browser()
    response=br.open("http://localhost/test.php")
    br.select_form('form1')
    br['uploadedfile']=open("C:/Documents and
    Settings/user/Desktop/Today/newurl-ideas.txt")
    response=br.submit()
    print response.read()

    But, i get the error:
    br['uploadedfile']=open("C:/Documents and
    Settings/user/Desktop/Today/newurl
    -ideas.txt")
    File
    "C:\Python25\lib\site-packages\clientform-0.2.9-py2.5.egg\ClientForm.py",
    line 2880, in __setitem__
    ValueError: value attribute is readonly

    But,
    When uploading is done using browser, it works.
    --
    Yours,
    S.Selvam


    --
    Yours,
    S.Selvam
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20081202/23584174/attachment-0001.htm>

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 2, '08 at 8:03a
activeDec 2, '08 at 8:40a
posts2
users1
websitepython.org

1 user in discussion

S.Selvam Siva: 2 posts

People

Translate

site design / logo © 2022 Grokbase