Odd error from Python3 text.find

I am searching a string for a substring. It seems simple enough:

i=text.find('Subject: [SpamCop]')

Unfortunately I am getting a traceback that makes no sense.

Traceback (most recent call last):
File “./spamcop.py”, line 109, in
scan(fin)
File “./spamcop.py”, line 51, in scan
i=text.find(‘Subject: [SpamCop]’)
TypeError: argument should be integer or bytes-like object, not ‘str’

Why would a string function complain about providing a string. It looks like it wants a 2nd and 3rd argument even though it is not required. Can someone help with this? TIA.

I’m guessing text is a bytes object rather than a str (you can try print(type(text)) to double-check). In Python 3, it’s mandatory to explicitly convert between the two instead of just mixing them together. So you could either call text.decode() to get a Unicode string version of text, or you can search for the bytes object b'Subject: [SpamCop]'.

Thanks. That was exactly it. Sometimes converting to Python3 is non-trivial.