gpt4 book ai didi

python - Kivy 无法从外部 URL 加载图像

转载 作者:行者123 更新时间:2023-12-01 06:49:15 25 4
gpt4 key购买 nike

我正在开发一个 Kivy 项目,该项目需要加载托管在外部 URL 中的图像我尝试过image=Image(source=https://www.gogoanime1.com/ac/meta/anime/8349/ghost-in-the-shell-movies.jpg)

并将其添加到我的布局中:layout.add_widgets(image)此处的错误不清楚,日志抛出此 *[ERROR ] [Image ] 读取文件时出错 https://www.gogoanime1.com/ac/meta/anime/8349/ghost-in-the-shell-movies.jpg *

我还尝试了 image=AsyncImage(https://www.gogoanime1.com/ac/meta/anime/8349/ghost-in-the-shell-movies.jpg)但它仍然失败,可能是由于用户代理的要求,错误日志是

[INFO   ] [Logger      ] Record log in C:\Users\DELL\.kivy\logs\kivy_19-11-29_23.txt
[INFO ] [deps ] Successfully imported "kivy_deps.gstreamer" 0.1.17
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.1.9
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.1.12
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.1.22
[INFO ] [Kivy ] v1.11.1
[INFO ] [Kivy ] Installed at "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\__init__.py"
[INFO ] [Python ] v3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Users\DELL\AppData\Local\Programs\Python\Python36\python.exe"
[INFO ] [Factory ] 184 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.5.0 NVIDIA 353.62'>
[INFO ] [GL ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO ] [GL ] OpenGL renderer <b'GeForce GT 525M/PCIe/SSE2'>
[INFO ] [GL ] OpenGL parsed version: 4, 5
[INFO ] [GL ] Shading version <b'4.50 NVIDIA'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Start application main loop
[INFO ] [Loader ] using a thread pool of 2 workers
[ERROR ] [Loader ] Failed to load image <https://www.gogoanime1.com/ac/meta/anime/8349/ghost-in-the-shell-movies.jpg>
Traceback (most recent call last):
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\loader.py", line 342, in _load_urllib
fd = opener.open(request)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 570, in error
return self._call_chain(*args)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
[ERROR ] [Loader ] Failed to load image <https://www.gogoanime1.com/ac/meta/anime/11100/ssssgridman.jpg>
Traceback (most recent call last):
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\loader.py", line 342, in _load_urllib
fd = opener.open(request)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 570, in error
return self._call_chain(*args)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
[INFO ] [WindowSDL ] exiting mainloop and closing.
[INFO ] [Base ] Leaving application in progress...

我该如何解决这个问题,也许使用请求库来加载图像。

最佳答案

pypi提供的kivy版本有bug该问题已在下一个版本中解决,因此在此之前您有以下选择:

  • 等待 kivy 的下一个版本,
  • 从 github 安装:pip install git+https://github.com/kivy/kivy.git,
  • 或修改 loader.py 文件(在您的情况下,它位于 C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\loader.py):
# ...
if (
Config.has_section('network')
and 'useragent' in Config.items('network')
):
# ...

if Config.has_option('network', 'useragent'):

我推荐最后一种方法,因为它比其他方法更简单、更快。

关于python - Kivy 无法从外部 URL 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59099017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com