TypeError: ListControl, should set the sequence (python error)

I use Python Mechanize to open a website, fill out a form, and submit this form. It is actually quite simple. It works until I am on the radio buttons and β€œselect” the input fields.

br.open(url)
br.select_form(name="postmsg")
br.form['subject'] = "Is this good for the holidays? "
br.form['message'] = "I'm new to technology."
br.form['E'] = '0'
br.submit()

  br.form['E'] = '0'
  File "build/bdist.linux-x86_64/egg/ClientForm.py", line 2897, in __setitem__
  File "build/bdist.linux-x86_64/egg/ClientForm.py", line 2092, in __setattr__
  File "build/bdist.linux-x86_64/egg/ClientForm.py", line 2100, in _set_value
TypeError: ListControl, must set a sequence

Why am I getting this error? Why can't I set E in the same way as text fields? (E - switch)

Edit: this is a form, according to the web developer.

Elements
Index   Id  Name    Type    Value   Label   Size    Maximum Length  State
0   subject subject text            35      
2   message message textarea                    
3   identity    identity    select          1       
13      action_btn  hidden                  
14      _charset_   hidden                  
16      r   hidden  /Stocks_(A_to_Z)/Stocks_G               
9       E   radio   0               

Checked
8       E   radio   1               
15      .crumb  hidden  1n1Yo3MQae3             
7       E   radio   2               
17      bn  hidden  25263               
6       E   radio   3               
5       E   radio   4               
4       E   radio   5               
12  SubmitCancel    SubmitCancel    submit  Cancel              
1   mbpostthreads   threads button  Check Existing Topics First             
11  SubmitPost  SubmitPost  submit  Post Message                
10  SubmitPreview   SubmitPreview   submit  Preview Message             
18  yIdCoreIdUser       hidden  annamae41g  
+5
source share
1 answer

Radio buttons and checkboxes may have different behavior than other elements. It depends on their name and identifier.

If the items have the same name, try this:

br.find_control(name="E").value = ["0"]

:

form.find_control(name="E", kind="list").value = ["0"]

, , :

    br["E"] = ["0"]

( , ).

+8

All Articles