ValueError: a checkbox must be set to a sequence

This is the place for queries that don't fit in any of the other categories.

ValueError: a checkbox must be set to a sequence

Postby alekz » Tue Jul 23, 2013 9:44 am

Friends, I need some help.. I want to make a script to search some data on the web-site using Grab library. For the appropriate search I need to tick some checkboxes with particular id="a3", "a4". So I do the following command: set_inpur_by_id('a3', True), where I get ValueError sth like "checkboxgroup must be set to a sequence (not True)". What's wrong?

The website is the following: [url]view-source:http://zakupki.gov.ru/pgz/public/action/contracts/search/ext/enter[/url].

I'd appreciate any help
Best,
Alexander
Last edited by alekz on Thu Jul 25, 2013 3:41 pm, edited 1 time in total.
alekz
 
Posts: 6
Joined: Tue Jul 23, 2013 9:35 am

Re: How to tick checkboxes using grab library?

Postby stranac » Tue Jul 23, 2013 11:00 am

Paste your code and the exact error traceback you are getting.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1092
Joined: Thu Feb 07, 2013 3:42 pm

Re: How to tick checkboxes using grab library?

Postby alekz » Tue Jul 23, 2013 11:44 am

>>> from grab import Grab
>>> g=Grab()
>>> g.go('http://zakupki.gov.ru/pgz/public/action/contracts/search/ext/enter')
<grab.response.Response object at 0x02A67830>
>>> g.set_input_by_id('a3', True)

Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
g.set_input_by_id('a3', True)
File "C:\Python27\lib\site-packages\grab-0.4.11-py2.7.egg\grab\ext\form.py", line 149, in set_input_by_id
return self.set_input(elem.get('name'), value)
File "C:\Python27\lib\site-packages\grab-0.4.11-py2.7.egg\grab\ext\form.py", line 135, in set_input
elem.value = value
File "C:\Python27\lib\site-packages\lxml\html\__init__.py", line 1308, in _value__set
% (self[0].name, value))
ValueError: A CheckboxGroup (name='a') must be set to a sequence (not True)
alekz
 
Posts: 6
Joined: Tue Jul 23, 2013 9:35 am

Re: How to tick checkboxes using grab library?

Postby alekz » Thu Jul 25, 2013 3:39 pm

Guys,
As I am kind of novice to python it is not easy to deal with this problem. Would you be so kind to help me to sort it out?
So, what I have is:
- there is some checkboxgroup with the common name "a"
- when I want to change some of checkboxes to True or False Python reports a ValueError: A checkboxgroup (name=%r) must be set to a sequence (not %r)
Then, as long as I understand, I need to find out correctly possible values of these checkboxes, right? If it is so, how can I do this?
The answer might be here http://sourcecodebrowser.com/lxml/2.1.1/src_2lxml_2html_2____init_____8py_source.html, line 1167 but I cannot understand how to use it anyway.
Any help will be highly appreciated, it is important
alekz
 
Posts: 6
Joined: Tue Jul 23, 2013 9:35 am

Re: ValueError: a checkbox must be set to a sequence

Postby Yoriz » Thu Jul 25, 2013 4:54 pm

It seems like it expects the 2nd argument to be a sequence not a single item.
If there was two checkboxes in the group and you want the first checked and the second not checked,
i guess it would be like this
Code: Select all
g.set_input_by_id('a3', (True, False))
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 721
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: ValueError: a checkbox must be set to a sequence

Postby alekz » Thu Jul 25, 2013 5:19 pm

Well, that seems reasonable, but nevertheless, it says there's no checkbox with value True.

In particular, there are 4 checkboxes in the group with id = "a1", "a2", "a3", "a4". Their values are "IN", "E", "ET", "EC", respectively. On default, "a2" is checked, and all the others - unchecked. I need "a2", "a3" and "a4" to be checked to do the search appropriately.

So I run g.set_input('a', (True, True, True, True)) and the Traceback is as follows:

Traceback (most recent call last):
File "<pyshell#150>", line 1, in <module>
g.set_input('a', (True, True, True, True))
File "C:\Python27\lib\site-packages\grab-0.4.11-py2.7.egg\grab\ext\form.py", line 135, in set_input
elem.value = value
File "C:\Python27\lib\site-packages\lxml\html\__init__.py", line 1309, in _value__set
self.value.update(value)
File "C:\Python27\lib\site-packages\lxml\html\_setmixin.py", line 72, in update
self.add(item)
File "C:\Python27\lib\site-packages\lxml\html\__init__.py", line 1347, in add
raise KeyError("No checkbox with value %r" % value)
KeyError: 'No checkbox with value True'
alekz
 
Posts: 6
Joined: Tue Jul 23, 2013 9:35 am

Re: ValueError: a checkbox must be set to a sequence

Postby Yoriz » Thu Jul 25, 2013 5:36 pm

Should you be using this method instead?
Code: Select all
def set_input(self, name, value):
        """
    Set the value of form element by its `name` attribute.

    :param name: name of element
    :param value: value which should be set to element

    To check/uncheck the checkbox pass boolean value.

    Example::

    g.set_input('sex', 'male')

    # Check the checkbox
    g.set_input('accept', True)
"""
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 721
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: ValueError: a checkbox must be set to a sequence

Postby alekz » Thu Jul 25, 2013 6:13 pm

What is the difference? I don't see how to implement this.
Are you talking about this source:
http://pydoc.net/Python/grab/0.3.12/grab.ext.lxml_form/
?
alekz
 
Posts: 6
Joined: Tue Jul 23, 2013 9:35 am

Re: ValueError: a checkbox must be set to a sequence

Postby Yoriz » Thu Jul 25, 2013 7:16 pm

Yes i just looked at the source, what about using a different module if you can't find info on how to use that one.
How do you select choices in a form using Python?
Checkbox input using python mechanize
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 721
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: ValueError: a checkbox must be set to a sequence

Postby alekz » Thu Jul 25, 2013 8:20 pm

I have tried this, but failed in the very beginning when Mechanize refused to do this:
br.open('http://zakupki.gov.ru/pgz/public/action/contracts/search/ext/enter/')

Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
br.open('http://zakupki.gov.ru/pgz/public/action/contracts/search/ext/enter/')
File "build\bdist.win32\egg\mechanize\_mechanize.py", line 203, in open
return self._mech_open(url, data, timeout=timeout)
File "build\bdist.win32\egg\mechanize\_mechanize.py", line 255, in _mech_open
raise response
httperror_seek_wrapper: HTTP Error 404: Not Found

It seems to be like a cursed task.. I just wanted to tick 2 checkboxes. I never imagined it might be that difficult..
alekz
 
Posts: 6
Joined: Tue Jul 23, 2013 9:35 am

Re: ValueError: a checkbox must be set to a sequence

Postby Yoriz » Thu Jul 25, 2013 8:30 pm

Dont know , have never had the need to try, btw that link in your last code has a / on the end making the link not even work if you put it into a browser.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 721
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests