0

I launched the Django project to maintain service. Then I got the following error.

UnicodeDecodeError at /register/
'utf-8' codec can't decode byte 0xb7 in position 3: invalid start byte 

It was very simple operation that render the page with template. Django says error happened in template file but it was decoded as UTF-8.

The working environments are,

- Python 3.6.10 installed by pyenv.
- Django 2.1.8
- macOS Catalina

Update!!

In error log, I found the erorr log about the mysql connection. I configured the test mysql DB externally in AWS RDS. So it would be the clue.

........
File "/Users/jinhoyoo/.pyenv/versions/3.6.10/envs/youha/lib/python3.6/site-packages/django/db/models/query.py" in _fetch_all
  1186.             self._result_cache = list(self._iterable_class(self))
File "/Users/jinhoyoo/.pyenv/versions/3.6.10/envs/youha/lib/python3.6/site-packages/django/db/models/query.py" in __iter__
  54.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/Users/jinhoyoo/.pyenv/versions/3.6.10/envs/youha/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1065.             cursor.execute(sql, params)
File "/Users/jinhoyoo/.pyenv/versions/3.6.10/envs/youha/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  100.             return super().execute(sql, params)
File "/Users/jinhoyoo/.pyenv/versions/3.6.10/envs/youha/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  68.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/Users/jinhoyoo/.pyenv/versions/3.6.10/envs/youha/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
  77.         return executor(sql, params, many, context)
File "/Users/jinhoyoo/.pyenv/versions/3.6.10/envs/youha/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)
File "/Users/jinhoyoo/.pyenv/versions/3.6.10/envs/youha/lib/python3.6/site-packages/django/db/backends/mysql/base.py" in execute
  71.             return self.cursor.execute(query, args)
........
Jinho Yoo
  • 1,352
  • 5
  • 17
  • 28

2 Answers2

1

B7 is hex for "middle dot" in latin1. It sounds like your client is using latin1, but your database setup is expecting utf8.

See "best practice" in Trouble with UTF-8 characters; what I see is not what I stored

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • Thanks, Rick. It's a good suggestion. In my case, all data and code were encoded as UTF-8. Only the mysql client has a problem. ;-) – Jinho Yoo Feb 11 '20 at 02:30
0

I found the reason. MySQL 8.0.19 version has the problem. You should use the mysql version under 8.0.18 as client.

You can install mysql client only by brew install mysql-client then you'll get the mysql client 8.0.18. Then reinstall mysqlclient python module by following https://github.com/PyMySQL/mysqlclient-python.

Jinho Yoo
  • 1,352
  • 5
  • 17
  • 28