Notes when using rpclib for Python Network Programming
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 is a very useful python webservice library that 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.
?
1 2 3 4 5 6 7 8 9 |
@ Srpc (RequestModel, _ returns = Unicode) Def shenzhen (request ): """ Based on the entered token, license plate number, vehicle license number, and verification code Query the violation records of the vehicle """ 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:
<Wsdl: documentation>
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:
</Wsdl: documentation>
No wonder an error occurs when you encounter a Chinese comment!
Note <>: For more exciting tutorials, please pay attention to the help house programming