This article mainly introduces the annotation problem when using rpclib for Python network programming. The author tells me that he needs to pay attention to unicode annotations when writing servers, for more information, see rpclib, which is a very useful python webservice library and can dynamically generate wsdl. However, this project has basically stopped and is replaced by spyne by a new project, since the work of the old project has been relatively stable, I did not rush to upgrade to spyne.
When I wrote the service method in rpclib, I encountered a strange error: Accessing wsdl (http: // localhost: 9898 /? The 502 Bad Gateway is returned.
The following error message is displayed in the log:
The Code is as follows:
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters
I checked the code, compared the previous versions that can work, and found that there is nothing wrong with it.
@ Srpc (RequestModel, _ returns = Unicode) def shenzhen (request): "based on the incoming token, license plate number, and vehicle driving number, and the verification code to query the violation record "" logging.info (request) query = ShenZhenQuery (request) return query. query_car_records ()
However, the wsdl is not correctly generated. Then I deleted all the content (including comments) in the method, leaving only one statement that returns the unicode string, and then it works normally, however, when I added a method document comment and came out with the previous error, I suspected that the Chinese comment did not use the unicode string, so after u "" Chinese note "is used, everything is normal!
View the generated wsdl and find that the original rpclib is generated using the annotation.
The Code is as follows:
Query the violation records of the Vehicle Based on the entered token, license plate number, vehicle driving number, and verification code.
The Code is as follows:
No wonder an error occurs when you encounter a Chinese comment!