Sandiph Bamrel
Sandiph Bamrel

Reputation: 147

Kivy Cannot Load Image from external URL

I am working on a Kivy project that requires for an image to be loaded which is hosted in external URL I tried it with image=Image(source=https://www.gogoanime1.com/ac/meta/anime/8349/ghost-in-the-shell-movies.jpg)

and adding it to my layout as layout.add_widgets(image) The error is not clear here the log throws this *[ERROR ] [Image ] Error reading file https://www.gogoanime1.com/ac/meta/anime/8349/ghost-in-the-shell-movies.jpg *

I also tried with image=AsyncImage(https://www.gogoanime1.com/ac/meta/anime/8349/ghost-in-the-shell-movies.jpg) But it still fails maybe due to requirement of User Agent and the error log is

[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...

how can i work around this , maybe using requests library to load image .

Upvotes: 1

Views: 749

Answers (1)

eyllanesc
eyllanesc

Reputation: 243897

The version of kivy provided by pypi has a bug which has been resolved for the next release, so before that you have the following options:

  • Wait for the next release of kivy,
  • Install from github: pip install git+https://github.com/kivy/kivy.git,
  • or Modify the loader.py file (in your case it is located in C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\kivy\loader.py) by changing:
# ...
if (
    Config.has_section('network')
    and 'useragent' in Config.items('network')
):
# ...

to

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

I recommend the last method because it is simpler and faster than the others.

Upvotes: 1

Related Questions