简体   繁体   中英

Python error: TypeError: a bytes-like object is required, not 'str'

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!

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'>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM