Python 3.x and TestLink xmlprc - python

Appreciate your helping first, I am new for the python 3.x.
When I try to use Python 3.x to parse the testlink xmlprc server. I got below error, but I can run the code under Python 2.x, any idea?
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.
Here is the 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

When I've seen this message before, it happened because the contents of the transported data wasn't escaped for XML transport. The solution was to wrap the data in an XMLRPC Binary object.
In your case, you don't control the server side, so the above isn't a solution for you but it may suggest what the actual problem is.
Also, the Python 2 versus Python 3 difference suggests that there is a text/bytes issue at work.
To help diagnose the issue, set verbose=True so you can see the actual HTTP request/response headers and the XML request/response. That may show you what is at line 2: column 0. You may find that the issue may be with the PHP script not wrapping up binary data in base64 encoding as required by the XMLRPC spec.

Thank you , I find out all the methods list, only 'tl.sayHello', 'tl.ping','tl.about' has this problem, and all of them are pass a string with a PHP automatic loader empty file *.class.php to the parser, other methods are pass a xml file. So I give up to use those methods and the script works fine.

Related

python strftime format variable

I'm using this prometheus json exporter https://github.com/catawiki/json_exporter and
I can't figure out how to use the strftime parameter. It is required to use the format from https://docs.python.org/3/library/time.html#time.strftime. As I understand a string should be defined. If I set:
strftime: '%Y-%m-%d'
and use the variable as
params:
start_date: $strftime
I have this error
Traceback (most recent call last):
File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/site-packages/json_exporter/main.py", line 257, in run
self.scrape()
File "/usr/local/lib/python2.7/site-packages/json_exporter/main.py", line 279, in scrape
data = render(self.body, variables)
File "/usr/local/lib/python2.7/site-packages/json_exporter/main.py", line 125, in render
return Template(tmpl).safe_substitute(variables)
File "/usr/local/lib/python2.7/string.py", line 207, in safe_substitute
return self.pattern.sub(convert, self.template)
TypeError: expected string or buffer
What is the correct way to use this ?
Thank you.
Everything seems to match with documentation, even if the documentation is not really clear about wether datetime.strftime or time.strftime fields are to be used (but interestingly, both know about %Y, event the latter).
Some things to try:
remove the quotes around your format template.
specify your template directly in the params, instead of using a link
Also, from the error stacktrace, you are running Python 2.7, which means:
the documentation you need is on this page. Not sure there would be a difference though.
you're 2 years out of active support period, and should seriously consider updating your system.

Python Dropbox API - Invalid "cursor" parameter

I've been migrating some Python 2.7.11 code to 3.5.1 after running into trouble with unicode. This was the last straw - since I started using the venv module there's no reason to be on 2.7 just because someone doesn't like 3!
The problem occurs while trying to run a one-way sync (ie. downloading changes only).
Here is the full error message, paths shortened:
Traceback (most recent call last):
File "%SCRIPT%.py", line 209, in <module>
updated_schedules = dbx_sync.One_Way_Sync(config['Dropbox Parameters']['Directory'], config['Dropbox Parameters']['Base Path'])
File "%COMMON_PATH%\modules\dropbox_sync_schedules.py", line 62, in One_Way_Sync
result = client.delta(cursor, base_path)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\client.py", line 569, in delta
return self.rest_client.POST(url, params, headers)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\rest.py", line 322, in POST
return cls.IMPL.POST(*n, **kw)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\rest.py", line 260, in POST
is_json_request=is_json_request)
File "%COMMON_PATH%\env-home\lib\site-packages\dropbox\rest.py", line 235, in request
raise ErrorResponse(r, r.read())
dropbox.rest.ErrorResponse: [400] 'Invalid "cursor" parameter: u"b\'\'"'
Searching for "invalid cursor parameter" wasn't any help, so I thought I'd come here.
u"b\'\'" is the key here. I just couldn't understand how that representation had ended up being sent as a string.
The issue was in reading the old cursor from a file (which for this example is empty): in Python 2 I had opened the file in mode rb - in Python 3 just r is all that's required, and everything works.
Hurrah!

ExpatError: no element found - Python script

Using OS X 10.6.8, libxml 2-2.7.8, libxslt-1.1.26, and python 2.6, I'm trying to run the tumblrRestore.py script linked here:
https://github.com/hughsaunders/Tumblr-Restore/blob/master/tumblrRestore.py
It ran successfully and restored 76 posts before crashing.
However on second run I got an ExpatError: no element found, and have not been able to run it successfully since - it always produces this same error now. Error text:
Tumblr Restore
Traceback (most recent call last):
File "tumblrRestore.py", line 264, in <module>
cli.start()
File "tumblrRestore.py", line 232, in start
bp.parse()
File "tumblrRestore.py", line 51, in parse
postelement=ElementTree.fromstring(xml_string)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/etree/ElementTree.py", line 964, in XM
return parser.close()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/etree/ElementTree.py", line 1254, in close
self._parser.Parse("", 1) # end of data
xml.parsers.expat.ExpatError: no element found: line 1, column 0
I'm wondering whether I have the wrong or competing or outdated versions of python or lxml, though that still doesn't explain why the script ran successfully once.
Complete newbie, any advice appreciated.
Check your extract_xml_string method of BackupParser class. It definitely returns empty string, because your begin_re regular expresssion doesn't match xml header.
Try the next one:
begin_re = re.compile("<\? xml .*\?>")

Suds + JIRA = SAXException

I'm using Python 2.6 and suds 0.3.7 to interact with JIRA 4.0.
When I connect to the JIRA server, I get information on all the issues just fine.
However, when I want to update an issue, I get a SAXException from suds (presumably):
WebFault: Server raised fault:
org.xml.sax.SAXException: Found character data inside an array element while deserializing
I'm following the steps described here: http://confluence.atlassian.com/display/JIRA/Creating+a+SOAP+Client
only replacing SOAPpy calls with suds.
My attempt to update an issue looks like this, complete with exceptions:
>>> w="http://bugs/rpc/soap/jirasoapservice-v2?wsdl"
>>> from suds.client import Client
>>> client = Client(w)
>>> auth = client.service.login("myname","mypass")
>>> issue = client.service.getIssue(auth,"BUG-30112")
>>> issue.summary
This is the original summary for BUG-30112
>>>
>>> client.service.updateIssue(auth,"BUG-30112",[
... {"id":"summary","values":["My new summary"]}])
Traceback (most recent call last):
File "<interactive input>", line 2, in <module>
File "C:\Python26\lib\suds\client.py", line 535, in __call__
return client.invoke(args, kwargs)
File "C:\Python26\lib\suds\client.py", line 595, in invoke
result = self.send(msg)
File "C:\Python26\lib\suds\client.py", line 630, in send
result = self.failed(binding, e)
File "C:\Python26\lib\suds\client.py", line 681, in failed
r, p = binding.get_fault(reply)
File "C:\Python26\lib\suds\bindings\binding.py", line 235, in get_fault
raise WebFault(p, faultroot)
WebFault: Server raised fault: 'org.xml.sax.SAXException: Found character data inside an array element while deserializing'
>>>
Has anyone seen a problem like this?
This will be solved if you switch to suds 3.0.9 (beta) ... the only one to have the fix.
How about increasing the verbosity to see what is being sent? Or use wireshark. You could also do the same with SOAPpy and compare exactly what is sent. Debugging soap errors is usually like this for me :-/
~Matt
Actually, by just changing the library from suds to SOAPpy, everything started working with no other modifications. Kind of annoying. I skipped SOAPpy because it seemed to have been abandoned and more complex to install, compared to suds. But SOAPpy works!
Thanks, all.

Yahoo BOSS Python Library, ExpatError

I tried to install the Yahoo BOSS mashup framework, but am having trouble running the examples provided. Examples 1, 2, 5, and 6 work, but 3 & 4 give Expat errors. Here is the output from ex3.py:
gpython examples/ex3.py
examples/ex3.py:33: Warning: 'as' will become a reserved keyword in Python 2.6
Traceback (most recent call last):
File "examples/ex3.py", line 27, in <module>
digg = db.select(name="dg", udf=titlef, url="http://digg.com/rss_search?search=google+android&area=dig&type=both&section=news")
File "/usr/lib/python2.5/site-packages/yos/yql/db.py", line 214, in select
tb = create(name, data=data, url=url, keep_standards_prefix=keep_standards_prefix)
File "/usr/lib/python2.5/site-packages/yos/yql/db.py", line 201, in create
return WebTable(name, d=rest.load(url), keep_standards_prefix=keep_standards_prefix)
File "/usr/lib/python2.5/site-packages/yos/crawl/rest.py", line 38, in load
return xml2dict.fromstring(dl)
File "/usr/lib/python2.5/site-packages/yos/crawl/xml2dict.py", line 41, in fromstring
t = ET.fromstring(s)
File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 963, in XML
parser.feed(text)
File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 1245, in feed
self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0
It looks like both examples are failing when trying to query Digg.com. Here is the query that is constructed in ex3.py's code:
diggf = lambda r: {"title": r["title"]["value"], "diggs": int(r["diggCount"]["value"])}
digg = db.select(name="dg", udf=diggf, url="http://digg.com/rss_search?search=google+android&area=dig&type=both&section=news")
The problem is the digg search string. It should be "s=". Not "search="
I believe that must be an error in the example: it's getting a JSON result (indeed if you copy and paste that URL in your browser, you'll download a file names search.json which starts with
{"results":[{"profile_image_url":
"http://a3.twimg.com/profile_images/255524395/KEN_OMALLEY_REVISED_normal.jpg",
"created_at":"Mon, 14 Sep 2009 14:52:07 +0000","from_user":"twilightlords",
i.e. perfectly normal JSON; but then instead of parsing it with modules such as json or simplejson, it tries to parse it as XML -- and obviously this attempt fails.
I believe the fix (which probably needs to be brought to the attention of whoever maintains that code so they can incorporate it) is either to ask for XML instead of JSON output, OR to parse the resulting JSON with appropriate means instead of trying to look at it as XML (not sure how to best implement either change, as I'm not familiar with that code).

Categories

Resources