Python mechanize:提交带有文件(图像)的表单?
有一个表单具有以下控件(它是一个上载图像控件) 我试过了Python mechanize:提交带有文件(图像)的表单?,python,image,browser,mechanize,Python,Image,Browser,Mechanize,有一个表单具有以下控件(它是一个上载图像控件) 我试过了 br.form['profile_image'] = open("img.jpg") 但是,我得到了错误 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: val
br.form['profile_image'] = open("img.jpg")
但是,我得到了错误
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
这样做:
br.form.add_file(open(FILENAME), 'text/plain', FILENAME)
br.form.set_all_readonly(False)
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
br.form.add_file(open(FILENAME), 'text/plain', FILENAME)
br.form.set_all_readonly(False)