Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASCIIHexCodec decoder not compatible with bytes object #83

Open
dcmvdbekerom opened this issue Jun 29, 2020 · 0 comments
Open

ASCIIHexCodec decoder not compatible with bytes object #83

dcmvdbekerom opened this issue Jun 29, 2020 · 0 comments

Comments

@dcmvdbekerom
Copy link

An exception is thrown when decoding objects with a ASCIIHEXCodec:

    fdata = fobj.getData()
  File "c:\users\dcmvd\documents\github\pypdf4\pypdf\generic.py", line 950, in getData
    decoded._data = decodeStreamData(self)
  File "c:\users\dcmvd\documents\github\pypdf4\pypdf\filters.py", line 757, in decodeStreamData
    data = ASCIIHexCodec.decode(data)
  File "c:\users\dcmvd\documents\github\pypdf4\pypdf\filters.py", line 249, in decode
    elif c.isspace():
AttributeError: 'int' object has no attribute 'isspace'

This is likely legacy Py2 code that was not updated to Py3. The problem can be solved easily by converting data to string in the beginning of the method:

 try:
       data = data.decode()
 except(AttributeError):
       pass

And converting the return value to str/byte depending on which python version is running at the end of the method:

retval = b_(retval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant