PyPDF4
PyPDF4 copied to clipboard
ASCIIHexCodec decoder not compatible with bytes object
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)