【问题标题】:Python 3.x and TestLink xmlprcPython 3.x 和 TestLink xmlprc
【发布时间】:2011-11-28 09:13:31
【问题描述】:

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

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

【问题讨论】:

    标签: python xml-rpc


    【解决方案1】:

    当我之前看到这条消息时,它的发生是因为传输的数据的内容没有为 XML 传输而转义。解决方案是将数据包装在 XMLRPC Binary object 中。

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

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

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

    【讨论】:

    • 嗨,雷,谢谢,我添加了详细 = True,我可以看到一个致命错误:[[[[[标题:日期标题:服务器标题:X-Powered-By标题:内容长度header: 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/') 在 /opt/lampp/htdocs/SITM/lib/functions/common.php102
      \n" ] ]]]
    • 我好像丢失了这个文件,但是这个文件是自动加载的。
    【解决方案2】:

    谢谢,我找到了所有方法列表,只有'tl.sayHello','tl.ping','tl.about'有这个问题,而且都是传一个PHP自动加载器为空的字符串文件 *.class.php 到解析器,其他方法是传递一个 xml 文件。所以我放弃使用这些方法,脚本运行良好。

    【讨论】:

      猜你喜欢
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多