lczub / TestLink-API-Python-client

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

testlink 1.9.20 createTestProject failed due to _checkResponse error #133

Closed sumoning closed 4 years ago

sumoning commented 4 years ago

when I create project with the keyword createTestProject , it returns me error

import testlink

url = 'http://10.2.48.153/lib/api/xmlrpc/v1/xmlrpc.php'
key = 'f97d9f4e6782cab3c12c87fb09432b77'

tlc = testlink.TestlinkAPIClient(url, key)

print tlc.createTestProject('测试', 'cs', active=1, public=1)
ssh://ubuntu@10.2.48.152:22/usr/bin/python -u /tmp/pycharm_project_446/testtestlink.py
Traceback (most recent call last):
  File "/tmp/pycharm_project_446/testtestlink.py", line 30, in <module>
    print tlc.createTestProject('测试', 'cs', active=1, public=1)
  File "/tmp/pycharm_project_446/testlink/testlinkdecorators.py", line 112, in wrapperAddDevKey
    return methodAPI(self, *argsPositional, **argsOptional)
  File "/tmp/pycharm_project_446/testlink/testlinkdecorators.py", line 100, in wrapperWithArgs
    *argsPositional, **argsOptional)
  File "/tmp/pycharm_project_446/testlink/testlinkapigeneric.py", line 1584, in callServerWithPosArgs
    self._checkResponse(response, methodNameAPI, argsOptional) 
  File "/tmp/pycharm_project_446/testlink/testlinkapigeneric.py", line 2167, in _checkResponse
    response[0]['message'], response[0]['code'])
testlink.testlinkerrors.TLResponseError: <exception str() failed>

Process finished with exit code 1

so I debug the error. I found the error in _checkResponse

    def _checkResponse(self, response, methodNameAPI, argsOptional):
        """ Checks if RESPONSE is empty or includes Error Messages
            Will raise TLRepsonseError in this case """
        if response:
            try:
                **_if 'code' in response[0]_**:
                    raise testlinkerrors.TLResponseError(
                                    methodNameAPI, argsOptional,
                                    response[0]['message'], response[0]['code'])
            except (TypeError, KeyError):
                # if the reponse has not a [{..}] structure, the check
                #    'code' in response[0]
                # raise an error. Following causes are ok
                # TypeError: raised from doesUserExist, cause the postiv 
                #            response is simply 'True'
                # KeyError: raise from uploadExecutionAttachment, cause the 
                #           positiv response is directly a dictionary
                pass
        else:
            raise testlinkerrors.TLResponseError(methodNameAPI, argsOptional,
                                                 'Empty Response! ')

there may should be if 'code' not in response[0]

sumoning commented 4 years ago

my error~this issue can be closed