Cannot access mSID - UnicodeDecodeError
Trying to access the "sed.mSID" value but it always returns an error:
*** UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 69: invalid start byte
OS: Ubuntu 18.04 Python 3.8.10
The client code (running as root) tries to access the device to query for basic information:
from TCGstorageAPI import tcgapi
sed = tcgapi.Sed(device)
print(f'WWN: {sed.wwn}')
print(f'mSID: {sed.mSID}')
----
5764824129321851479
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/TCGstorageAPI/tcgapi.py", line 276, in mSID
return self.__pysed.mSID
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 69: invalid start byte
This code worked fine before the Python3 conversion. Any suggestions?
Following up: The bug is in the TcgDrive.cpp Session::dumpPacket function. dump packet tries to turn the packet data into a C-String using "c_str()", however, the packet data is not guaranteed to be UTF-8 (the default for c_str()) and thus will abort when it hits a character that cannot be decoded (0xFF, 0xFE, etc).
Workaround: set "_debugPackets = False" in the python client code.
Fix: Fix the Session::dumpPackets function to properly display the hex bytes from the packet dump without using std::string.c_str().
TCGstorageAPI/tcgapi.py does not expose the _debugPackets value as a settable property.
So, client code has to use a hacky solution like:
sed._Sed__pysed._debugPackets = False
So, in addition to the dumpPacket problem above, tcgapi.py has a bug in that it doesn't expose the API to enable/disable packet dumps.
Pull request submitted with fixes.
Merged pull request