django.core.serializers.base.DeserializationError:安装设备“/opt/my-api/mynetwork_common/设备/表情符号组. json”时出现问题

bttbmeg0  于 2023-03-20  发布在  Go
关注(0)|答案(1)|浏览(85)

我在GCP Ubuntu 22.04上运行Django 3.2和docker的Django rest API,当我运行Web服务器容器时,我收到一个错误:
django.core.serializers.base.DeserializationError:安装设备“/opt/my-api/mynetwork_common/设备/表情符号组. json”时出现问题
详细轨迹如下:

my-api-webserver | Traceback (most recent call last):
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/serializers/json.py", line 69, in Deserializer
my-api-webserver |     objects = json.loads(stream_or_string)
my-api-webserver |   File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
my-api-webserver |     return _default_decoder.decode(s)
my-api-webserver |   File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
my-api-webserver |     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
my-api-webserver |   File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
my-api-webserver |     raise JSONDecodeError("Expecting value", s, err.value) from None
my-api-webserver | json.decoder.JSONDecodeError: Expecting value: line 11 column 28 (char 266)
my-api-webserver | 
my-api-webserver | The above exception was the direct cause of the following exception:
my-api-webserver | 
my-api-webserver | Traceback (most recent call last):
my-api-webserver |   File "manage.py", line 25, in <module>
my-api-webserver |     execute_from_command_line(sys.argv)
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
my-api-webserver |     utility.execute()
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
my-api-webserver |     self.fetch_command(subcommand).run_from_argv(self.argv)
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
my-api-webserver |     self.execute(*args, **cmd_options)
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
my-api-webserver |     output = self.handle(*args, **options)
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/modeltranslation/management/commands/loaddata.py", line 49, in handle
my-api-webserver |     return super(Command, self).handle(*fixture_labels, **options)
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 78, in handle
my-api-webserver |     self.loaddata(fixture_labels)
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 123, in loaddata
my-api-webserver |     self.load_label(fixture_label)
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 181, in load_label
my-api-webserver |     for obj in objects:
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/serializers/json.py", line 74, in Deserializer
my-api-webserver |     raise DeserializationError() from exc
my-api-webserver | django.core.serializers.base.DeserializationError: Problem installing fixture '/opt/my-api/mynetwork_common/fixtures/emoji-groups.json':

引发错误的文件是:

[
  {
    "model": "mynetwork_common.EmojiGroup",
    "pk": 1,
    "fields": {
      "order": 1,
      "keyword": "primary",
      "keyword_en": "Primary",
      "color": "#FFFFFF",
      "created": "2018-10-22 12:23:30.382913+00:00",
      "is_reaction_group": True,
      "keyword_es": "",
      "keyword_de": "Standard",
      "keyword_sv": "Primära",
      "keyword_fr": "Principales",
      "keyword_it": "Principale",
      "keyword_tr": "Başlıca",
      "keyword_pt_br": "Básico"
    }
  },
  {
    "model": "mynetwork_common.EmojiGroup",
    "pk": 2,
    "fields": {
      "order": 2,
      "keyword": "obgold",
      "keyword_en": "Premium",
      "color": "#FFFFFF",
      "created": "2018-10-22 12:23:30.382913+00:00",
      "is_reaction_group": True,
      "keyword_es": "",
      "keyword_de": "Premium",
      "keyword_sv": "Premium",
      "keyword_fr": "Prémium",
      "keyword_it": "Premium",
      "keyword_tr": "Premium",
      "keyword_pt_br": "Premium"
    }
  },
  {
    "model": "mynetwork_common.EmojiGroup",
    "pk": 3,
    "fields": {
      "order": 2,
      "keyword": "objects",
      "keyword_en": "Objects",
      "color": "#FFFFFF",
      "created": "2018-10-22 12:23:30.382913+00:00",
      "is_reaction_group": false,
      "keyword_es": "",
      "keyword_de": "Objekte",
      "keyword_sv": "Objekt",
      "keyword_fr": "Objets",
      "keyword_it": "Tipi",
      "keyword_tr": "Nesneler",
      "keyword_pt_br": "Objetos"
    }
  }
]

我以前没有遇到过这个文件的问题。这个问题突然出现了。感谢帮助。
编辑:正如Alombaros建议的解决方案,我确实将布尔值从“True”改为---〉“true”。
但是,上述错误已消失,但出现了同一文件中的新错误:

KeyError: 'keyword_sv
django.core.exceptions.FieldDoesNotExist: EmojiGroup has no field named 'keyword_sv'

接着是同样的错误:

django.core.serializers.base.DeserializationError: Problem installing fixture '/opt/my-api/mynetwork_common/fixtures/emoji-groups.json'

这里是models.py

class EmojiGroup(models.Model):
    keyword = models.CharField(_('keyword'), max_length=32, blank=False, null=False)
    color = models.CharField(_('color'), max_length=COLOR_ATTR_MAX_LENGTH, blank=False, null=False,
                             validators=[hex_color_validator], unique=False)
    order = models.IntegerField(unique=False, default=100)
    created = models.DateTimeField(editable=False)
    is_reaction_group = models.BooleanField(_('is reaction group'), default=False)

    def __str__(self):
        return 'EmojiGroup: ' + self.keyword

    def save(self, *args, **kwargs):
        ''' On save, update timestamps '''
        if not self.id:
            self.created = timezone.now()
        return super(EmojiGroup, self).save(*args, **kwargs)

    def has_emoji_with_id(self, emoji_id):
        return self.emojis.filter(pk=emoji_id).exists()
idfiyjo8

idfiyjo81#

如追溯中所表达的,解析器不理解值行11列28。
这是因为“True”不是JSON布尔值,您应该使用“True”代替(您在第二个时间行30中遇到了相同的错误)
我不确定您要用不同的语言做什么,但在我看来,应该从JSON中删除每个“keyword_XX”

相关问题