2011-11-28 58 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文件。所以我放棄使用這些方法,腳本工作正常。