z/OS Tools & Language

Python 3.7 encode/decode issue for z/OS USS

  • 1.  Python 3.7 encode/decode issue for z/OS USS

    Posted 03-06-2020 10:21

    I have a python program that goes through USS directories to look for a certain file with a certain text and writes out the text if that text is not desired. This program was working with binary files coming into program. The issue is now with text files coming in. I am guessing the files coming in are EBCDIC with encoding cp1047.

    The output error I am seeing is:

    Traceback (most recent call last):
    File “/opt/lpp/Rocket-ported/miniconda/lib/python3.7/tokenize.py”, line 385, in find_cookie
    line_string = line.decode(‘utf-8’)
    UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xc1 in position 2: invalid start byte

    I have tried setting encoding to cp500 with command with open(os.path.join(dirpath, filename), mode = ‘r’, encoding = ‘cp500’) as settingsfile: , and that doesn’t work and produces the above error.