Python异常处理TypeError: translation() got an unexpected keyword argument ‘codeset‘

背景

学习graphql-python安装好依赖后执行命令

python manage.py migrate
python manage.py runserver

仅接着出现下列错误,主要提示是 「TypeError: translation() got an unexpected keyword argument ‘codeset’」

ntribute_to_class
    self.remote_field.through = create_many_to_many_intermediary_model(self, cls)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/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 "/Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/site-packages/django/utils/functional.py", line 149, in __mod__
    return str(self) % rhs
           ^^^^^^^^^
  File "/Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/site-packages/django/utils/functional.py", line 113, in __text_cast
    return func(*self.__args, **self.__kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/site-packages/django/utils/translation/__init__.py", line 75, in gettext
    return _trans.gettext(message)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/site-packages/django/utils/translation/trans_real.py", line 286, in gettext
    _default = _default or translation(settings.LANGUAGE_CODE)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/site-packages/django/utils/translation/trans_real.py", line 199, in translation
    _translations[language] = DjangoTranslation(language)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/site-packages/django/utils/translation/trans_real.py", line 90, in __init__
    self._init_translation_catalog()
  File "/Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/site-packages/django/utils/translation/trans_real.py", line 131, in _init_translation_catalog
    translation = self._new_gnu_trans(localedir)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/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'



        return gettext_module.translation(
            domain=self.domain,
            localedir=localedir,
            languages=[self.__locale],
            codeset='utf-8',
            fallback=use_null_fallback,
        )



分析与解决

根据异常栈定位到源代码位置 /Users/software_1/miniconda3/envs/learnLangchain/lib/python3.11/site-packages/django/utils/translation/trans_real.py,代码调用python方法传入参数codeset

        return gettext_module.translation(
            domain=self.domain,
            localedir=localedir,
            languages=[self.__locale],
            codeset='utf-8',
            fallback=use_null_fallback,
        )

当前python版本为3.11,源码查看并没有该参数。随后看了教程文章,前置依赖要求是python3.6。 接着看了一下Django版本为2.1.4,所以是版本间冲突导致。

解决:最终有两种解决方式,升级Django版本或者切换python版本

  1. 查看Django最新版依赖要求,升级到最新版解决问题。
  2. 使用python3.6

相关推荐

  1. Python异常处理

    2024-01-02 08:40:07       39 阅读
  2. python--异常处理

    2024-01-02 08:40:07       41 阅读
  3. Python爬虫--异常处理

    2024-01-02 08:40:07       27 阅读
  4. Python异常处理

    2024-01-02 08:40:07       36 阅读
  5. Python异常处理

    2024-01-02 08:40:07       32 阅读
  6. python 异常处理、随机数、

    2024-01-02 08:40:07       31 阅读
  7. Python异常处理

    2024-01-02 08:40:07       20 阅读
  8. Python 异常处理

    2024-01-02 08:40:07       21 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-02 08:40:07       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-02 08:40:07       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-02 08:40:07       82 阅读
  4. Python语言-面向对象

    2024-01-02 08:40:07       91 阅读

热门阅读

  1. 分布式【RPC 常见面试题】

    2024-01-02 08:40:07       48 阅读
  2. 举例说明计算机视觉(CV)技术的优势和挑战

    2024-01-02 08:40:07       58 阅读
  3. C语言【程序设计题10】

    2024-01-02 08:40:07       56 阅读
  4. 服务器的关键参数指标

    2024-01-02 08:40:07       51 阅读
  5. 服务器如何设置禁ping,禁ping有哪些作用

    2024-01-02 08:40:07       55 阅读
  6. 服务器安装Mysql5.7

    2024-01-02 08:40:07       58 阅读
  7. 力扣135. 分发糖果

    2024-01-02 08:40:07       55 阅读