Notes when using rpclib for Python Network Programming

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.