user7987788
user7987788

Reputation: 13

TypeError: argument should be integer or bytes-like object, not 'str'

i have a problem with a string. This is the code:

if x.find("Sensor")!=-1 :

The error that comes out to me is the following:

if x.find("Sensor")!=-1 :
TypeError: argument should be integer or bytes-like object, not 'str'

I think I need to convert the string to binary. Do you have any idea how to do it?

Thank you all

Upvotes: 1

Views: 8564

Answers (2)

Danrley Perez Sena
Danrley Perez Sena

Reputation: 29

You need to check if you are analyzing a string or a byte object. If it is a byte object you just decode it, example:

element = b'Content to be searched'
string_element = element.decode('UTF-8')
string_element.find('word you are looking for')

Upvotes: 2

U13-Forward
U13-Forward

Reputation: 71580

It means your string is a bytes object, so try:

if x.find(b"Sensor")!=-1 :

Upvotes: 6

Related Questions