2011-11-28 62 views
0

首先感谢您的帮助,我是python 3.x的新手。 当我尝试使用Python 3.x来解析testlink xmlprc服务器时。我得到了以下错误,但我可以在Python 2.x下运行代码,任何想法?Python 3.x和TestLink xmlprc

import xmlrpc.client 

server = xmlrpc.client.Server("http://172.16.29.132/SITM/lib/api/xmlrpc.php") //here is my testlink server 
print (server.system.listMethods()) //I can print the methods list here 
print (server.tl.ping()) // Got error. 

以下是错误:

['system.multicall', 'system.listMethods', 'system.getCapabilities', 'tl.repeat', 'tl.sayHello', 'tl.ping', 'tl.setTestMode', 'tl.about', 'tl.checkDevKey', 'tl.doesUserExist', 'tl.deleteExecution', 'tl.getTestSuiteByID', 'tl.getFullPath', 'tl.getTestCase', 'tl.getTestCaseAttachments', 'tl.getFirstLevelTestSuitesForTestProject', 'tl.getTestCaseCustomFieldDesignValue', 'tl.getTestCaseIDByName', 'tl.getTestCasesForTestPlan', 'tl.getTestCasesForTestSuite', 'tl.getTestSuitesForTestSuite', 'tl.getTestSuitesForTestPlan', 'tl.getLastExecutionResult', 'tl.getLatestBuildForTestPlan', 'tl.getBuildsForTestPlan', 'tl.getTotalsForTestPlan', 'tl.getTestPlanPlatforms', 'tl.getProjectTestPlans', 'tl.getTestPlanByName', 'tl.getTestProjectByName', 'tl.getProjects', 'tl.addTestCaseToTestPlan', 'tl.assignRequirements', 'tl.uploadAttachment', 'tl.uploadTestCaseAttachment', 'tl.uploadTestSuiteAttachment', 'tl.uploadTestProjectAttachment', 'tl.uploadRequirementAttachment', 'tl.uploadRequirementSpecificationAttachment', 'tl.uploadExecutionAttachment', 'tl.createTestSuite', 'tl.createTestProject', 'tl.createTestPlan', 'tl.createTestCase', 'tl.createBuild', 'tl.setTestCaseExecutionResult', 'tl.reportTCResult'] 
Traceback (most recent call last): 
File "F:\SQA\Python\Testlink\Test.py", line 5, in <module> 
    print (server.tl.ping()) 
File "C:\Python31\lib\xmlrpc\client.py", line 1029, in __call__ 
    return self.__send(self.__name, args) 
File "C:\Python31\lib\xmlrpc\client.py", line 1271, in __request 
    verbose=self.__verbose 
File "C:\Python31\lib\xmlrpc\client.py", line 1070, in request 
    return self.parse_response(resp) 
File "C:\Python31\lib\xmlrpc\client.py", line 1164, in parse_response 
    p.feed(response) 
File "C:\Python31\lib\xmlrpc\client.py", line 454, in feed 
    self._parser.Parse(data, 0) 
xml.parsers.expat.ExpatError: junk after document element: line 2, column 0 

回答

0

当我以前见过这个消息时,它的发生是因为所传输的数据的内容并没有逃过XML传输。解决方案是将数据包装在XMLRPC Binary object中。

在你的情况下,你不控制服务器端,所以上述不是你的解决方案,但它可能表明实际问题是什么。

此外,Python 2与Python 3的差异表明在工作中存在文本/字节问题。

要帮助诊断问题,请设置verbose=True,以便您可以看到实际的HTTP请求/响应标头和XML请求/响应。这可能会告诉你什么是line 2: column 0。您可能会发现问题可能出在PHP脚本没有按照XMLRPC spec的要求以base64编码包装二进制数据。

+0

嗨,Ray,谢谢,我添加verbose = True,并且我可以看到一个致命错误:[[[[[header:Date header:服务器标头:X-Powered-By标头:Content-Length标头:Content-Type header:X-Pad body:b“
\ n 致命错误:require_once()[function.require]:无法打开所需的'Hello!.class.php'(include_path ='。:/ opt/lampp/lib/php: 。/ opt/lampp/htdocs/SITM/lib/functions /:/ opt/lampp/htdocs/SITM/third_party /')
\ n“]]]] – kbm1422

+0

看起来我缺少这个文件,但是这个文件是自动加载的。 – kbm1422

0

谢谢,我找到了所有的方法列表,只有'tl.sayHello','tl.ping','tl.about'有这个问题,并且它们都是用PHP自动装载器传递一个字符串空文件* .class.php到解析器,其他方法都是通过一个xml文件。所以我放弃使用这些方法,脚本工作正常。