Python3: "can't do nonzero cur-relative seeks"; with python2.7 shebang it works

I have a script generated with 2to3.
With “python3” shebang gives error.
“io.UnsupportedOperation: can’t do nonzero cur-relative seeks”
The very same script with “python2.7” shebang works.
Message sounds non-sensical to me non-zero current-relative seek is the useful kind, and the zero relative seek is a noop.

I would like to get proper Python3 script to work.
Any help will be much appreciated.

Python 3 open() defaults to text mode or encoded character data. This means there isn’t necessarily a 1:1 relationship between bytes and characters.

From the documentation

In text files (those opened without a b in the mode string), only seeks relative to the beginning of the file are allowed (the exception being seeking to the very file end with seek(0, 2) ) and the only valid offset values are those returned from the f.tell() , or zero. Any other offset value produces undefined behaviour.

If your file is not UTF-8, you can open it in 'b’inary mode and seek() around.