lczub / TestLink-API-Python-client

A Python client to use the TestLink API
105 stars 63 forks source link

py3 - TestLinkExample.py under py34 - TypeError: expected bytes-like object, not str #39

Closed lczub closed 9 years ago

lczub commented 9 years ago

executing TestLinkExampleGenericApi.py and TestLinkExample.py under py33 and py34 fails with

...
getTestCaseBugs TC_AA in TP_A (TC is not executed) [{'id': -1}]
reportTCResult [{'message': 'Success!', 'status': True, 'overwrite': False, 'id': '1145', 'operation': 'reportTCResult'}]
getTestCaseBugs TC_AA in TP_A (TC is executed, no bug) [{'bugs': []}]
reportTCResult [{'message': 'Success!', 'status': True, 'overwrite': False, 'id': '1146', 'operation': 'reportTCResult'}]
reportTCResult [{'message': 'Success!', 'status': True, 'overwrite': False, 'id': '1147', 'operation': 'reportTCResult'}]
Traceback (most recent call last):
  File "D:\Projekte\git\TestLink-API-Python-client\.tox\py34\lib\base64.py", line 519, in _input_type_check
    m = memoryview(s)
TypeError: memoryview: str object does not have the buffer interface

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "example\TestLinkExample.py", line 483, in <module>
    filename='MyPyExampleApiClient.py')
  File "D:\Projekte\git\TestLink-API-Python-client\.tox\py34\lib\site-packages\testlink\testlinkdecorators.py", line 156, in wrapperAddAttachment
    argsAttachment = self._getAttachmentArgs(attachmentfile)
  File "D:\Projekte\git\TestLink-API-Python-client\.tox\py34\lib\site-packages\testlink\testlinkapigeneric.py", line 1241, in _getAttachmentArgs
    'content':base64.encodestring(attachmentfile.read())
  File "D:\Projekte\git\TestLink-API-Python-client\.tox\py34\lib\base64.py", line 548, in encodestring
    return encodebytes(s)
  File "D:\Projekte\git\TestLink-API-Python-client\.tox\py34\lib\base64.py", line 536, in encodebytes
    _input_type_check(s)
  File "D:\Projekte\git\TestLink-API-Python-client\.tox\py34\lib\base64.py", line 522, in _input_type_check
    raise TypeError(msg) from err
TypeError: expected bytes-like object, not str
ERROR: InvocationError: 'D:\\Projekte\\git\\TestLink-API-Python-client\\.tox\\py34\\Scripts\\python.EXE example\\TestLinkExample.py'

Reproduction: call tox with commit 034e995

lczub commented 9 years ago

Analysis: TestlinkAPIGeneric._getAttachmentArgs() uses base64.encodestring(s), which expects under py2 a string s. Under py34, this is a deprecated alias for the new method base64.encodestring(s), which expects a binary string s.

More details compare

lczub commented 9 years ago

fixed with release v0.6.0