Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: translation() got an unexpected keyword argument 'codeset'

I'm following a Python tutorial on youtube and need to create a django website, however I am unable to start, because when I enter "python manage.py runserver" I get the "TypeError: translation() got an unexpected keyword argument 'codeset'" message. I've run back the video like 20 times to see if I've missed anything, but no, because it's just the beginning of the django website tutorial. I've also tried typing python3 instead of python and some other options I saw on Stack Overflow, but none are really exactly relevant to the error message I'm getting. Perhaps someone knows how to fix this?

I tried to start a development server by typing in "python manage.py runserver" which was supposed to start a django webserver at 127.0.0.1:8000 or something, but instead I got the error message specified in the title

code:

PS C:\Users\kaspa\PycharmProjects\PyShop> python manage.py runserver
Exception ignored in thread started by: <function check_errors.<locals>.wrapper at 0x00000145784C1F80>
Traceback (most recent call last):
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
    raise _exception[1]
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\apps\registry.py", line 112, in populate
    app_config.import_models()
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\apps\config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\contrib\auth\models.py", line 94, in <module>
    class Group(models.Model):
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\base.py", line 139, in __new__
    new_class.add_to_class(obj_name, obj)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\base.py", line 304, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\fields\related.py", line 1583, in contribute_to_class
    self.remote_field.through = create_many_to_many_intermediary_model(self, cls)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\db\models\fields\related.py", line 1051, in create_many_to_many_intermediary_model
    'verbose_name': _('%(from)s-%(to)s relationship') % {'from': from_, 'to': to},
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\functional.py", line 149, in __mod__
    return str(self) % rhs
           ^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\functional.py", line 113, in __text_cast
    return func(*self.__args, **self.__kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\__init__.py", line 75, in gettext
    return _trans.gettext(message)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 286, in gettext
    _default = _default or translation(settings.LANGUAGE_CODE)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 199, in translation
    _translations[language] = DjangoTranslation(language)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 90, in __init__
    self._init_translation_catalog()
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 131, in _init_translation_catalog
    translation = self._new_gnu_trans(localedir)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kaspa\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\translation\trans_real.py", line 119, in _new_gnu_trans
    return gettext_module.translation(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: translation() got an unexpected keyword argument 'codeset

'

like image 878
Kaspar Avatar asked Sep 07 '25 03:09

Kaspar


1 Answers

I've also been following Mosh's Python course, ran into the same problem, came here for answers and then did some more research on my own.

I'm a total beginner, I might me wrong, but in the tutorial, Mosh makes us install django 2.1 instead of the current version of django. The error "translation() got an unexpected keyword argument 'codeset'" basically means that python thinks there shouldn't be an argument called 'codeset' after the gettext_module.translation( that is in the code created with/(used in?) django 2.1.

Turns out, in the python gettext documentation, "Changed in version 3.11: codeset parameter is removed.". So django 2.1 has some code that isn't reconized by python 3.11, which pops an error.

Solution:

1- Deleted my python "PyShop" project.

2- Closed PyCharm.

3- Created a new "PyShop" project.

4- In the terminal, typed "pip uninstall django".

5- Then installed the current version of django by typing "pip install django" in the terminal (not pip install django==2.1 as shown in the tutorial).

6- Created the "pyshop" folder by typing "django-admin startproject pyshop ." in the terminal.

7- Typed "python manage.py runserver" in the terminal.

And voila! No more error, because the current version of django doesn't create stuff with code that the current version of python doesn't recognize in it.

New to python and stack overflow, sorry for some things I maybe wrote wrong or something :)

like image 103
William Laflamme Avatar answered Sep 10 '25 07:09

William Laflamme