Htmltestrunner solution unicodedecodeerror: ' ASCII ' codec can ' t decode byte 0xe5 in position 108:ordinal not in range (128)

Source: Internet
Author: User

Where the HTML and database are set to UTF-8 format encoding, inserted into the database is correct, but when read out of error, because the Python str default is ASCII encoding, and Unicode encoding conflict, will report this header error. So how to solve it?

Through the collection of online information, their own attempts, the problem is solved, in the code to add the following sentence can be.

SYSReload(sys)sys.  Setdefaultencoding(' UTF8 ')         

Http://docs.python.org/howto/unicode.html This is the Python Unicode encoding API documentation, English good students can look, deepen understanding.

Reference: Http://groups.google.com/group/python-cn/browse_thread/thread/f48ef745452740f6?pli=1

Click to open link

--------------------------------------------------------------------------------------------------------------- ---------

The STR and Unicode data types inside the Python2 are confused.

0.

What you need is for the code to be actually coded instead of ASCII.

1.

For code that needs Str->unicode, you can write it in the front

Import Sys

Reload (SYS)

Sys.setdefaultencoding (' utf8′)

Change STR encoding from ASCII to UTF8 (or GB18030)

2.

Python3 distinguishes between Unicode STR and byte arrary, and the default encoding is no longer ASCII

Htmltestrunner solution unicodedecodeerror: ' ASCII ' codec can ' t decode byte 0xe5 in position 108:ordinal not in range (128)

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.