Python error solution: SyntaxError: Non-ASCII character & amp; #39; \ xd3 & amp; #39; in file crawler. py

Source: Internet
Author: User

I encountered Encoding Problems in the python code I wrote: SyntaxError: Non-ASCII character '\ xd3' in file crawler. py


Cause: the Code contains a part that needs to output Chinese characters, but this error occurs during running;

Error prompted to see this link: http://www.python.org/peps/pep-0263.html


Solution:

If any character other than ASCII code appears in python, you must declare the character format at the beginning of the Code.


Solution:

Add #-*-coding: UTF-8-*-at the beginning of the program -*-

~ Test] # cat crawler. py
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
Import urllib2
Import re

Solution 2:

Add # coding: UTF-8 at the beginning of the program

#! /Usr/bin/python
# Coding: UTF-8
Import urllib2
Import re

Solution 3:

Add the following code at the beginning of the program: # coding = UTF-8

#! /Usr/bin/python
# Coding = UTF-8
Import urllib2
Import re

Related Article

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.