[SOLVED] - PYTHON - could not deal with some special chars

Discussion and information for XML-RPC interface.

Moderators: Amaradana, TurboPT, TL Developers

[SOLVED] - PYTHON - could not deal with some special chars

Postby wbai » Wed Jul 07, 2010 6:05 am

When I used get getTestCasesForTestSuite, in most cases, it could work smoothly, but I found that if some special characters are included in the case, I will get the error like following:
Traceback (most recent call last):
File "testlinkapi.py", line 128, in <module>
client.getProjectPlanTree('Wireline Test Plan')
File "testlinkapi.py", line 64, in getProjectPlanTree
testcaselistinsuite = self.getcasesinsuite(testsuite['id'])
File "testlinkapi.py", line 48, in getcasesinsuite
caselist = client.server.tl.getTestCasesForTestSuite(dict(devKey=self.devKey, testsuiteid=suiteid))
File "/usr/local/lib/python2.6/xmlrpclib.py", line 1199, in __call__
return self.__send(self.__name, args)
File "/usr/local/lib/python2.6/xmlrpclib.py", line 1490, in __request
File "/usr/local/lib/python2.6/xmlrpclib.py", line 1253, in request
return self._parse_response(h.getfile(), sock)
File "/usr/local/lib/python2.6/xmlrpclib.py", line 1388, in _parse_response
File "/usr/local/lib/python2.6/xmlrpclib.py", line 601, in feed
self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 205, column 72

I found that the case is like following:
CAM-17900: Delete Policy Server From 'All' Group, and the response is like:
<member><name>name</name><value><string>Delete Policy Server From the �ALL�

I have tried this when not setting encoding or set encoding to UTF-8, but all get this same error. I used python to implement this, and I searched the documents on xmlrpclib, it is said:
When passing strings, characters special to XML such as <, >, and & will be automatically escaped. However, it’s the caller’s responsibility to ensure that the string is free of characters that aren’t allowed in XML, such as the control characters with ASCII values between 0 and 31 (except, of course, tab, newline and carriage return); failing to do this will result in an XML-RPC request that isn’t well-formed XML. If you have to pass arbitrary strings via XML-RPC, use the Binary wrapper class described below.

But "'" seems not included in the invalid characters set. Have you experienced this problem before, do you have some good ideas on how to solve this problem? Thank you.
TestLink user
Posts: 2
Joined: Wed Jul 07, 2010 5:48 am

Re: could not deal with some special characters with xml-rpc

Postby mouse_chan » Thu Dec 30, 2010 7:30 am

I also have this problem. Is it resolved?
TestLink user
Posts: 3
Joined: Thu Dec 30, 2010 6:51 am

Re: could not deal with some special characters with xml-rpc

Postby fman » Thu Dec 30, 2010 8:54 am

do some search on our mantis and in this forum
Member of TestLink Community
Posts: 3062
Joined: Tue Nov 15, 2005 7:19 am

Re: could not deal with some special characters with xml-rpc

Postby akang » Sat Jan 29, 2011 1:20 am

For python user only:
This is how you debug which test case has special character.

[1] modify xmlrpclib.py which should be at your pyhton's lib. For example: /opt/Python25/lib/xmlrpclib.py
looking for def feed() at class ExpatParser
change it to:
def feed(self, data):
self._parser.Parse(data, 0)
except Exception, ex:
import traceback
trace_msg = traceback.format_exc()
print "[ExpatParser feed] catch exception.\nError message:%s\nDATA:\n%s" % (trace_msg, data)

[2] looking at the console output and you might be able to figure out which test case cause problem.

[3] in mysql console, do following step to correct it (if test case being executed you can not change from UI):
suppose the offending test case name is "Group <special char> Activity"
select * from nodes_hierarchy where name like "Group%Activity";
find the id, say it is 888
update nodes_hierarchy set name = "Group Activity" where id = 888
Advanced user
Posts: 20
Joined: Wed Sep 22, 2010 8:36 pm

Return to XML-RPC API

Who is online

Users browsing this forum: No registered users and 1 guest