有一个带有以下控件的表单(它是一个上传图像控件)
<FileControl(profile_image=<No files added>)>
我认为应该放在“??????????”中:
br = mechanize.Browser()
br.open(mywebsite)
br.select_form(nr=1)
br.form['profile_image'] = ??????????
br.submit()
我试过
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
答案 0 :(得分:6)
这样做:
br.form.add_file(open(FILENAME), 'text/plain', FILENAME)
br.form.set_all_readonly(False)