使用mechanize提交表单时出现TypeError:ListControl,必须设置序列

8 投票
1 回答
7070 浏览
提问于 2025-04-17 12:25

我正在尝试用 mechanize 提交一个表单,但遇到了一个错误(TypeError: ListControl, must set a sequence)。我在网上查了很久,试了几种不同的解决办法,但还是没能解决这个问题。我想提交所有的字段。

通过 mechanize 获取的表单数据(用 br.forms() 获取,打印出来:f)

<POST http://www.example.com/takeupload.php multipart/form-data
<HiddenControl(MAX_FILE_SIZE=1000000) (readonly)>
<TextControl(<None>=http://www.example.com:81/test.php?pass=550) (readonly)>
<FileControl(file=<No files added>)>
<TextControl(name=)>
<SelectControl(type=[*0, 23, 22, 1, 10, 7, 18, 4, 21, 56, 20, 60, 5, 19, 6, 55, 63, 9])>
<CheckboxControl(strip=[strip])>
<FileControl(nfo=<No files added>)>
<TextareaControl(descr=)>
<SubmitControl(<None>=Do it!) (readonly)>>

这是我现在的代码

br.open('http://www.bitfarm.co.za/upload.php')

br.select_form(nr=4)

filename = 'test.torrent'
br.form.add_file(open(filename), 'application/x-bittorrent', filename, name='file') 
br.form['name'] = 'test'
br.form['type'] = '22'
br.form['strip'] = '0'
br.form['nfo'] = ''
br.form['descr'] = 'This is the desc'

br.submit()

请帮我看看,我在表单选项的语法上是否正确。谢谢!

1 个回答

14

type 字段需要你提供一个整数的列表,但你只提供了一个整数。
把这个:

br.form['type'] = '22'

改成这个:

br.form['type'] = ['22',]

撰写回答