Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

python - Submitting a form with mechanize (TypeError: ListControl, must set a sequence)

I'm trying to submit a form with mechanize but have run into an error (TypeError: ListControl, must set a sequence) After googling for some time and trying a couple of different solutions I haven't been able to solve the issue. I'm trying to submit all the fields.

The form data fetched via mechanize (for f in br.forms() print: 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)>>

My current code

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()

Please could you assist and check I'm using the right syntax for the form options. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

type field expects a list of integers from you, but you provide just one integer.
Change this:

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

to this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...