Wagtail встроил видео с YouTube json ошибка декодирования - PullRequest
0 голосов
/ 03 августа 2020

Я сейчас использую wagtail version 2.9.3, и у меня возникают следующие ошибки при попытке загрузить URL-адрес YouTube в трясогузку.

JSONDecodeError at /admin/pages/3/edit/
Expecting value: line 1 column 1 (char 0)

Вот полная трассировка ошибок:

Internal Server Error: /admin/pages/3/edit/
Traceback (most recent call last):
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\admin\urls\__init__.py", line 109, in wrapper
    return view_func(request, *args, **kwargs)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\admin\auth.py", line 188, in decorated_view
    return view_func(request, *args, **kwargs)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\admin\views\pages.py", line 380, in edit
    if form.is_valid() and not page_perms.page_locked():
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\modelcluster\forms.py", line 315, in is_valid
    form_is_valid = super(ClusterForm, self).is_valid()
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\django\forms\forms.py", line 180, in is_valid
    return self.is_bound and not self.errors
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\django\forms\forms.py", line 175, in errors
    self.full_clean()
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\django\forms\forms.py", line 376, in full_clean
    self._clean_fields()
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\django\forms\forms.py", line 394, in _clean_fields
    value = field.clean(value)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\core\blocks\base.py", line 543, in clean
    return self.block.clean(value)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\core\blocks\stream_block.py", line 198, in clean
    (child.block.name, child.block.clean(child.value), child.id)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\core\blocks\struct_block.py", line 129, in clean
    result.append((name, self.child_blocks[name].clean(val)))
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\core\blocks\struct_block.py", line 129, in clean
    result.append((name, self.child_blocks[name].clean(val)))
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\embeds\blocks.py", line 69, in clean
    if isinstance(value, EmbedValue) and not value.html:
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\embeds\blocks.py", line 22, in html
    return embed_to_frontend_html(self.url)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\embeds\format.py", line 9, in embed_to_frontend_html
    embed = embeds.get_embed(url)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\embeds\embeds.py", line 24, in get_embed
    embed_dict = finder(url, max_width)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\embeds\embeds.py", line 20, in finder
    return finder.find_embed(url, max_width=max_width)
  File "C:\Users\dream\Desktop\NoboCMS\backend\cms_env\lib\site-packages\wagtail\embeds\finders\oembed.py", line 64, in find_embed
    oembed = json.loads(r.read().decode('utf-8'))
  File "C:\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python38\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Вот мой код:

Видеоблок

class VideoBlock(blocks.StructBlock):
'''rich text'''
content = blocks.StructBlock(
        [
        ("title",blocks.CharBlock(required=True, help_text="Add your Title")),
        ("video", EmbedBlock())
        ]
)

class Meta:
    icon = "edit"
    label = "Video Block"

Модель страницы, которая его использует

class HomePage(Page):
    '''home page model'''
    content = StreamField(
        [
            ("video",block.VideoBlock()),
        ] , blank=True
    )
    max_count = 1
    content_panels = [
        StreamFieldPanel('content'),
    ] + Page.content_panels 

    class Meta:
        verbose_name = "Home Page"
        verbose_name_plural = "Home Pages"

Я не знаю, как действовать дальше, и буду признателен за любую предоставленную помощь. Я использую URL-адрес видео: https://youtu.be/I4JnXn_WcQQ

.
...