Python Forum
post data problemHi guys I have small problem in python.I'm getting this error: "PO - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: post data problemHi guys I have small problem in python.I'm getting this error: "PO (/thread-9640.html)



post data problemHi guys I have small problem in python.I'm getting this error: "PO - jure98 - Apr-20-2018

Hi guys

I have small problem in python.I'm getting this error:

Error:
"POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str."
in this line:

response = self.br.open(loginform_url, data=urllib.parse.urlencode({'login':self.name, 'password':self.password}), timeout=35)
Thanks


RE: post data problemHi guys I have small problem in python.I'm getting this error: "PO - nilamo - Apr-20-2018

Does the error persist if you coerce the data as a bytes object? Something like:
data = urllib.parse.urlencode({"some": "data"})
response = self.br.open(loginform_url, data=data.encode(), timeout=35)



RE: post data problemHi guys I have small problem in python.I'm getting this error: "PO - jure98 - Apr-20-2018

now i'm getting this
Error:
a bytes-like object is required, not 'str'



RE: post data problemHi guys I have small problem in python.I'm getting this error: "PO - jure98 - Apr-22-2018

bump...


RE: post data problemHi guys I have small problem in python.I'm getting this error: "PO - snippsat - Apr-22-2018

You have given little info about what you use,are you using now older Python Mechanize?
For Post data is Requests or selenium if JavaScripts make problems,common to use.
Are you using Python 3?

Quote:a bytes-like object is required, not 'str'
No seeing all code this is just guessing,you can try convert str to bytes.
>>> s = 'hello'
>>> type(s)
<class 'str'>
>>> 
>>> # To bytes
>>> s = s.encode()
>>> s
b'hello'
>>> type(s)
<class 'bytes'>