Python Forum
how to solve "a bytes-like object is required, not 'str'" error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to solve "a bytes-like object is required, not 'str'" error
#1
Hi All,

Am getting the following error, while writing a string to process using write method in python 3, and it works very well for python 2.

I have googled it and found encode() and decode. When I encode the string to utf-8 while writing, it executes without an error, however the output returns is not as expected (not as python 2 output).

This is my code snippet
process.stdin.write('exit\n')
getting the following error
 File "test5.py", line 8, in <module>
process.stdin.write('exit\n'))
TypeError: a bytes-like object is required, not 'str'
Could any one please suggest/help me out to solve this issue, would be much appreciated. Thank you.

Regards,
Maiya
Reply


Messages In This Thread
how to solve "a bytes-like object is required, not 'str'" error - by maiya - Jul-28-2020, 06:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 6,979 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  Need help with 'str' object is not callable error. Fare 4 870 Jul-23-2023, 02:25 PM
Last Post: Fare
  TypeError: a bytes-like object is required ZeroX 13 4,265 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  TypeError: a bytes-like object is required, not 'str' - Help Please. IanJ 3 4,859 Aug-29-2022, 05:53 PM
Last Post: deanhystad
  Error in Int object is not subscript-able. kakut 2 1,206 Jul-06-2022, 08:31 AM
Last Post: ibreeden
Question how to solve `'TypeError: 'int' object is not iterable`? netanelst 2 1,610 May-24-2022, 12:03 PM
Last Post: deanhystad
  bytes object saved as .mp4 jttolleson 10 5,937 Feb-25-2022, 02:42 PM
Last Post: jttolleson
  how can I solve fsolve function error? troddydeeneeeeeey 3 2,480 Oct-14-2021, 07:07 PM
Last Post: deanhystad
  error : "Microsoft Visual C++ 14.0 is required. " Even its installed Barak 4 4,058 Oct-13-2021, 10:39 PM
Last Post: Underscore
  python 3: TypeError: a bytes-like object is required, not 'str' wardancer84 3 6,541 Jul-09-2021, 05:55 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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