POST method form in raises TypeError with submit_form in python3
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Triaged
|
Medium
|
Unassigned |
Bug Description
I'm getting an error while trying to submit a form that uses the POST method. I've posted on StackExchange ( http://
The minimal reproduction of the problem (this site responds to the
post with 404, but the error is in submission):
> >>> import lxml.html
> >>> page = lxml.html.parse("http://
> >>> form = page.getroot(
> >>> form.fields[
> >>> result = lxml.html.
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/
> return open_http(
> File "/usr/lib/
> return urlopen(url, data)
> File "/usr/lib/
> return opener.open(url, data, timeout)
> File "/usr/lib/
> req = meth(req)
> File "/usr/lib/
> raise TypeError(msg)
> TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.
Line 3 (setting the 'your_name' field) can be changed to use a bytes
object or omitted yet give the same result.
This works as expected in python2.
I'm using python3 on Arch Linux. Following your bug procedure I dumped the library versions:
Python : sys.version_
lxml.etree : (3, 0, 1, 0)
libxml used : (2, 8, 0)
libxml compiled : (2, 8, 0)
libxslt used : (1, 1, 26)
libxslt compiled : (1, 1, 26)
And those on python2
Python : sys.version_
lxml.etree : (3, 0, 1, 0)
libxml used : (2, 8, 0)
libxml compiled : (2, 8, 0)
libxslt used : (1, 1, 26)
libxslt compiled : (1, 1, 26)
Looks like the form data doesn't get encoded before sending. That would be a typical Py2 bug. Would be nice if you could come up with a patch. You can create a pull request on github.