Python error: TypeError: a bytes-like object is required, not 'str'
25,181
TypeError
implies that there is a mismatch in the datatype required vs given data's type. The function requires input of type 'bytes' while the code inputs data of type 'str'.
To convert the input string into byte-like object use str.encode
function.
>>> string = "abcdef"
>>> type(string)
<class 'str'>
>>> string = string.encode('ascii')
>>> type(string)
<class 'bytes'>
Related videos on Youtube
Comments
-
KayaP over 3 years
i'm working to a personal project and i'm confronting a error:
TypeError: a bytes-like object is required, not 'str'
Here is my code: CLICK TO SEE THE CODE
I want to make this script that is trying to find into the file a input text. Thanks!
-
Martijn Pieters over 4 yearsSorry, we can't accept images of code, data or errors. Post those as text, so that we can try to reproduce the problem without having to re-type everything, and your question can be properly indexed or read by screen readers.
-