In this tutorial, we will introduce on how to fix SyntaxError: Non-UTF-8 code starting with. From this tutorial, we will learn why this error occur and know how to fix it.
Look at code below.
import re str = u'这个是我的blog网站:https://www.tutorialexample.com'
In line 2, this error occurs.
Why this error occur?
The reason is str is a unicode string and is encoded by utf-8. However, our test.py file is not utf-8 encoding.
How to fix this error?
Set test.py file to be utf-8 encoding.
Then you may find the value of str is garbled, then change it. Finally, this error is fixed.