Solution to unicodedecodeerror in ntpath join (path, * paths)

Source: Internet
Author: User

I recently learned how to use python to develop Web applications. I used a Web framework. When I installed SAE and flask on win8.1, I always reported an error in the unicodedecodeerror module ntpath. py.

Row 84 result_path = result_path + p_path

The displayed error is the unicodedecodeerror ASCII/Unicode can not decode 0xc3 range 128 error. This error was also encountered when installing Sae. The error was found because my user name is Chinese and the Chinese Unicode code is \ xc3 \ xf8.

When the Unicode code encode is used, this path name is forcibly considered to be two ASCII codes and cannot exceed 128. Therefore, this error is caused.

At this time, I want to use Unicode () to forcibly convert two strings into Unicode, or not, because the Unicode () operation is to extend ascill to Unicode code, it also verifies whether the asill code is valid or whether the unicodedecodeerror error Unicode can not decode 0xc3 range 128 is reported.

Result_path = Unicode (result_path) + Unicode (p_path)

At this time, I thought about how to prevent it from being verified. I tried the STR () function to convert all the two codes into the STR type.

Result_path = STR (result_path) + STR (p_path)

At this time, the error does not appear and works normally, because converting the Unicode code to the STR type will not verify the ascill code, but will convert it into two eight-bit char (just saying, PY has no char type)

  

>>> A = 'hello'
>>> A [0]
'\ Xc4'

>>>
'\ Xc4 \ xe3 \ Xba \ xc3'
>>> Type ()
<Type 'str'>

 

In the case of Unicode code and STR type merge operations, you can forcibly convert them to STR type for merge, so there is no similar error.

In C: \ python27 \ Lib \ ntpath. py, replace the 84 rows result_path = result_path + p_path with result_path = STR (result_path) + STR (p_path)

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.