开发者

Python mechanize: Submitting a form with a file (image)?

There's a form with the following control (it's an upload image开发者_开发知识库 control)

<FileControl(profile_image=<No files added>)>

What am I supposed put in the "??????????":

br = mechanize.Browser()
br.open(mywebsite)
br.select_form(nr=1)
br.form['profile_image'] = ??????????
br.submit()

I've tried

   br.form['profile_image'] = open("img.jpg")

but get the error

  File "/usr/local/lib/python2.6/dist-packages/mechanize-0.2.4-py2.6.egg/mechanize/_form.py", line 2784, in __setitem__
    raise ValueError(str(e))
ValueError: value attribute is readonly


Do this:

br.form.add_file(open(FILENAME), 'text/plain', FILENAME)
br.form.set_all_readonly(False)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜