If you encounter a "Unicode Decode Error" in Python

I'm making a system with Python now, but when I registered the DB in Japanese, I encountered the following error.

error


UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in range(128)

At the time of the test, I knew that Japanese was bad because it was registered normally in English. If you google the error content, you will come across the following site and solve it with haste.

PS: Frequently visited pages on Google Analytics ...

index.py


import sys, codecs
# 3.5 =>
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)

import io
# 3.6 =< 3.x
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

Referenced site What to do if you get a UnicodeDecodeError when executing a Python script

Recommended Posts

If you encounter a "Unicode Decode Error" in Python
[Python] What to check when you get a Unicode Decode Error in Django
BigQuery-If you get a Reason: responseTooLarge error in Python
What to do if a Unicode Encode Error occurs in Sublime Text Python
Why do you add a main ()-if statement in Python?
What to do if you get a minus zero in Python
If you want to assign csv export to a variable in python
Check if you can connect to a TCP port in Python
If you want a singleton in python, think of the module as a singleton
If you get a Programming Error: (1146, "Table'<table name>' doesn't exist") in Django
What happens if you do "import A, B as C" in Python?
If you get a no attribute error in boto3, check the version
Use a custom error page in python / tornado
What to do if you get a "No versions found" error in pipenv
A solution if you accidentally remove the python interpreter in / usr / local / bin /.
Check if the string is a number in python
Until you insert data into a spreadsheet in Python
When you get an error in python scraping (requests)
What to do if you get an error when importing matplotlib in Python (Mac)
Understand Python yield If you put yield in a function, it will change to a generator
What to do if you run python in IntelliJ and end with an error
Take a screenshot in Python
Create a function in Python
Slice error in python (´ ; ω ; `)
Draw a heart in Python
Solution if you get 0xxx ascii coding error in superset
If you write TinderBot in Python, she can do it
How to import a file anywhere you like in Python
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do if you get Swagger-codegen in python and Import Error: No module named
Solution if the module is installed in Python but you get an error in Jupyter notebook
What to do if you get a Cannot retrieve metalink for repository error in yum
Maybe in a python (original title: Maybe in Python)
Write a binary search in Python
If you know Python, you can make a web application with Django
[python] Manage functions in a list
Hit a command in Python (Windows)
If you get stuck in Cannot load mkl_intel_thread.dll in Python on Windows
Create a DI Container in Python
Here are some grammars that you might get a slapstick face if you know it in Python
Draw a scatterplot matrix in python
Until you put Python in Docker
ABC166 in Python A ~ C problem
Write A * (A-star) algorithm in Python
Delete a particular character in Python if it is the last
A pretty sloppy Python error solution
Solve ABC036 A ~ C in Python
Write a pie chart in Python
Write a vim plugin in Python
Python2 str / unicode and encode / decode
Write a depth-first search in Python
What to do if you get a must override `get_config` error when trying to model.save in Keras
Implementing a simple algorithm in Python 2
Create a Kubernetes Operator in Python
Solve ABC037 A ~ C in Python
Run a simple algorithm in Python
Draw a CNN diagram in Python
Create a random string in Python
Schedule a Zoom meeting in Python
When writing a program in Python
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb