Python Forum
post data problemHi guys I have small problem in python.I'm getting this error: "PO
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
post data problemHi guys I have small problem in python.I'm getting this error: "PO
#1
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
Reply
#2
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)
Reply
#3
now i'm getting this
Error:
a bytes-like object is required, not 'str'
Reply
#4
bump...
Reply
#5
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'>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is the error of not being able to pull data in this code? i didn't see an error? TestPerson 2 1,203 Sep-30-2022, 02:36 PM
Last Post: DeaD_EyE
  Post HTML Form Data to API Endpoints Dexty 0 1,392 Nov-11-2021, 10:51 PM
Last Post: Dexty
  POST request with form data issue web scraping hoff1022 1 2,672 Aug-14-2020, 10:25 AM
Last Post: kashcode
  How to POST html data to be handled by a route endpoint nikos 1 2,373 Mar-07-2020, 03:14 PM
Last Post: nikos
  Sending data post to wsgiref JohnnyCoffee 0 1,780 Oct-24-2019, 09:04 PM
Last Post: JohnnyCoffee
  Python/BeautiifulSoup. list of urls ->parse->extract data to csv. getting ERROR IanTheLMT 2 3,963 Jul-04-2019, 02:31 AM
Last Post: IanTheLMT
  Error in requests.post debanilroy 3 5,414 Sep-18-2018, 06:15 PM
Last Post: snippsat
  How do i loop through list of data from CSV file and post requests in aspx dynamics w Prince_Bhatia 1 6,076 Nov-09-2017, 02:53 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020