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

Discussion and information for XML-RPC interface.

Moderators: Amaradana, TurboPT, TL Developers

Post Reply
wbai
TestLink user
Posts: 2
Joined: Wed Jul 07, 2010 5:48 am

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

Post by wbai »

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
verbose=self.__verbose
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
p.feed(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:
</struct></value>
<value><struct>
<member><name>id</name><value><string>38128</string></value></member>
<member><name>parent_id</name><value><string>37890</string></value></member>
<member><name>node_type_id</name><value><string>3</string></value></member>
<member><name>node_order</name><value><string>2</string></value></member>
<member><name>node_table</name><value><string>testcases</string></value></member>
<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.
mouse_chan
TestLink user
Posts: 3
Joined: Thu Dec 30, 2010 6:51 am

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

Post by mouse_chan »

I also have this problem. Is it resolved?
fman
Member of TestLink Community
Posts: 3123
Joined: Tue Nov 15, 2005 7:19 am

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

Post by fman »

do some search on our mantis and in this forum
akang
Advanced user
Posts: 20
Joined: Wed Sep 22, 2010 8:36 pm

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

Post by akang »

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):
try:
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
Post Reply