stephenmcd / mezzanine

CMS framework for Django

Home Page:http://mezzanine.jupo.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fresh install with MySQL/MariaDB: KeyError: <class 'bytes'>

eggnstone opened this issue · comments

  • Create new MySQL DB
  • Create new python project using PyCharm and Virtualenv
  • pip install mezzanine
  • pip install mysqlclient
  • mezzanine-project TestMysql .
  • Adjust local_settings.py to use mysql
  • python manage.py createdb --noinput

=> KeyError: <class 'bytes'>

Environment:

  • Windows 10
  • XAMPP 3.3.0
  • MariaDB 10.4.21-MariaDB - mariadb.org binary distribution
Traceback (most recent call last):
  File "C:\TestMySQL\manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "C:\TestMySQL\venv\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "C:\TestMySQL\venv\lib\site-packages\django\core\management\__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\TestMySQL\venv\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\TestMySQL\venv\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "C:\TestMySQL\venv\lib\site-packages\mezzanine\core\management\commands\createdb.py", line 39, in handle
    if "conf_setting" in connection.introspection.table_names():
  File "C:\TestMySQL\venv\lib\site-packages\django\db\backends\base\introspection.py", line 53, in table_names
    with self.connection.cursor() as cursor:
  File "C:\TestMySQL\venv\lib\site-packages\django\db\backends\base\base.py", line 254, in cursor
    return self._cursor()
  File "C:\TestMySQL\venv\lib\site-packages\django\db\backends\base\base.py", line 229, in _cursor
    self.ensure_connection()
  File "C:\TestMySQL\venv\lib\site-packages\django\db\backends\base\base.py", line 213, in ensure_connection
    self.connect()
  File "C:\TestMySQL\venv\lib\site-packages\django\db\backends\base\base.py", line 189, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\TestMySQL\venv\lib\site-packages\django\db\backends\mysql\base.py", line 276, in get_new_connection
    conn.encoders[SafeBytes] = conn.encoders[bytes]
KeyError: <class 'bytes'>

pip list:

Package                 Version
----------------------- -----------
beautifulsoup4          4.10.0
bleach                  4.1.0
certifi                 2021.10.8
chardet                 4.0.0
charset-normalizer      2.0.7
Django                  1.11.29
django-contrib-comments 2.0.0
filebrowser-safe        1.0.0
future                  0.18.2
grappelli-safe          1.0.0
idna                    3.3
Mezzanine               4.3.1
mysqlclient             2.1.0
oauthlib                3.1.1
packaging               21.3
Pillow                  8.4.0
pip                     21.1.2
pyparsing               3.0.6
pytz                    2021.3
pytz-deprecation-shim   0.1.0.post0
requests                2.26.0
requests-oauthlib       1.3.0
setuptools              57.0.0
six                     1.16.0
soupsieve               2.3.1
tzdata                  2021.5
tzlocal                 4.1
urllib3                 1.26.7
webencodings            0.5.1
wheel                   0.36.2

Hello, I have tried to reproduce the issue with Mezzanine 5.0, Django 3.2, Python 3.8 and MySQL 5.7. I actually first got a different error: incorrect string value. I fixed it by following the advice from this Stack Overflow post.

In summary, you need to create your tables with the correct encoding (utf8) AND set Django's database options to {"charset": "utf8mb4"}. After that the demo data set is loaded without problem.


You can also avoid this situation altogether by adding the --nodata flag to the createdb command. This will skip the gallery creation, which is the part having trouble storing an image with the name Ávila Spain.jpg (notice the accent on the first A).

Didn't receive a response so I'm closing the issue for now. Feel free to re-open with more details.