Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncImage - Failed to load image #5864

Closed
realslimshanky opened this issue Jul 18, 2018 · 4 comments
Closed

AsyncImage - Failed to load image #5864

realslimshanky opened this issue Jul 18, 2018 · 4 comments
Assignees

Comments

@realslimshanky
Copy link

Versions

  • Python: v3.5.3
  • OS: Debian GNU/Linux 9
  • Kivy: v1.11.0.dev0, git-1828af3, 20180623
  • Kivy installation method: pipenv install --skip-lock git+http://github.com/kivy/kivy.git#egg=kivy-1.10.1

Description

I tried using AsyncImage to load https://cdn-images-1.medium.com/max/800/1*RO3AhbppPUFJBZwt3gUW-A.png which is failing with error HTTP Error 403: Forbidden

Possible Solution: Adding proper headers before making the request using urllib as being done here in loader module

Code and Logs

main.py

from kivy.config import Config
Config.set('kivy', 'log_level', 'debug')

from kivy.app import App

class TestApp(App):
    def build(self):
        self.load_kv('./main.kv')


if __name__ == '__main__':
    TestApp().run()

main.kv

BoxLayout
    AsyncImage
        source: 'https://cdn-images-1.medium.com/max/800/1*RO3AhbppPUFJBZwt3gUW-A.png'
        canvas:
            Color:
                rgb: [1, 1, 1]
            Rectangle:
                texture: self.texture
                size: self.width + 20, self.height + 20
                pos: self.x - 10, self.y - 10

python main.py (logs)

[INFO   ] [Logger      ] Record log in /home/realslimshanky/.kivy/logs/kivy_18-07-18_83.txt
[INFO   ] [Kivy        ] v1.11.0.dev0, git-0471549, 20180718
[INFO   ] [Python      ] v3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118]
[INFO   ] [Factory     ] 194 symbols loaded
[DEBUG  ] [Cache       ] register <kv.lang> with limit=None, timeout=None
[DEBUG  ] [Cache       ] register <kv.image> with limit=None, timeout=60
[DEBUG  ] [Cache       ] register <kv.atlas> with limit=None, timeout=None
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[DEBUG  ] [Cache       ] register <kv.texture> with limit=1000, timeout=60
[DEBUG  ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600
[DEBUG  ] [App         ] Loading kv <./test.kv>
[DEBUG  ] [App         ] kv <./test.kv> not found
[DEBUG  ] [App         ] Loading kv </home/realslimshanky/Kivy/app/main.kv>
[DEBUG  ] [Window      ] Ignored <egl_rpi> (import error)
[INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[DEBUG  ] [GL          ] glShaderBinary is not available
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <b'3.0 Mesa 13.0.6'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel Open Source Technology Center'>
[INFO   ] [GL          ] OpenGL renderer <b'Mesa DRI Intel(R) HD Graphics 520 (Skylake GT2) '>
[INFO   ] [GL          ] OpenGL parsed version: 3, 0
[INFO   ] [GL          ] Shading version <b'1.30'>
[INFO   ] [GL          ] Texture max size <8192>
[INFO   ] [GL          ] Texture max units <32>
[DEBUG  ] [Shader      ] Fragment compiled successfully
[DEBUG  ] [Shader      ] Vertex compiled successfully
[DEBUG  ] [ImageSDL2   ] Load </home/realslimshanky/.local/share/virtualenvs/app-o_-EAHWa/lib/python3.5/site-packages/kivy/data/glsl/default.png>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[DEBUG  ] [Cache       ] register <kv.loader> with limit=500, timeout=60
[INFO   ] [Loader      ] using a thread pool of 2 workers
[DEBUG  ] [ImageGIF    ] Load </home/realslimshanky/.local/share/virtualenvs/app-o_-EAHWa/lib/python3.5/site-packages/kivy/data/images/image-loading.gif>
[DEBUG  ] [Base        ] Create provider from mouse
[INFO   ] [Base        ] Start application main loop
[ERROR  ] [Loader      ] Failed to load image <https://cdn-images-1.medium.com/max/800/1*RO3AhbppPUFJBZwt3gUW-A.png>
Traceback (most recent call last):
  File "/home/realslimshanky/.local/share/virtualenvs/app-o_-EAHWa/lib/python3.5/site-packages/kivy/loader.py", line 317, in _load_urllib
    fd = urllib_request.urlopen(filename)
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.5/urllib/request.py", line 510, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
[DEBUG  ] [Atlas       ] Load </home/realslimshanky/.local/share/virtualenvs/app-o_-EAHWa/lib/python3.5/site-packages/kivy/data/images/defaulttheme.atlas>
[DEBUG  ] [Atlas       ] Need to load 1 images
[DEBUG  ] [Atlas       ] Load </home/realslimshanky/.local/share/virtualenvs/app-o_-EAHWa/lib/python3.5/site-packages/kivy/data/images/defaulttheme-0.png>
[DEBUG  ] [ImageSDL2   ] Load </home/realslimshanky/.local/share/virtualenvs/app-o_-EAHWa/lib/python3.5/site-packages/kivy/data/images/defaulttheme-0.png>
@KeyWeeUsr KeyWeeUsr added Component: Widgets kivy/uix, style.kv Status: Needs-analysis Issue needs to be analyzed if it's real needs-unittest labels Jul 30, 2018
@tito tito added this to todo in Sprint pycon-fr 2018 via automation Oct 4, 2018
@tshirtman tshirtman moved this from todo to working in Sprint pycon-fr 2018 Oct 4, 2018
@tshirtman
Copy link
Member

Seems this host is filtering on the user agent, we can open the url with clients like eog which display fine, or with wget, but not with GET (link to lwp-request a perl script, on my system), using a GET command from an http shell, only changing user-id makes the issue come and go. So we could certainly change the user agent in kivy, but you never know what will be the policy of the server, so it's not going to be a proper general solution.

@tshirtman tshirtman added awaiting-reply Waiting for reply from issue opener, will be closed if no reply and removed Status: Needs-analysis Issue needs to be analyzed if it's real needs-unittest Component: Widgets kivy/uix, style.kv labels Oct 4, 2018
@tshirtman tshirtman moved this from working to done in Sprint pycon-fr 2018 Oct 4, 2018
@tshirtman
Copy link
Member

Thinking a bit more, the actual issue is that you can't set the required parameter on the loader class from user code, It seems like the simple solution would be to give a global kivy option, something like "useragent", in a new "network" section. and use this value in both UrlRequest and Loader (as it uses urllib directly).

@tito tito moved this from done to todo in Sprint pycon-fr 2018 Oct 5, 2018
tshirtman added a commit that referenced this issue Oct 5, 2018
@tshirtman tshirtman moved this from todo to done in Sprint pycon-fr 2018 Oct 7, 2018
@tito tito closed this as completed in 8bb99d6 Oct 7, 2018
Sprint pycon-fr 2018 automation moved this from done to closed Oct 7, 2018
@realslimshanky
Copy link
Author

Thanks @tito, works like a charm 🌮

@no-response no-response bot removed the awaiting-reply Waiting for reply from issue opener, will be closed if no reply label Oct 8, 2018
@no-response no-response bot reopened this Oct 8, 2018
Sprint pycon-fr 2018 automation moved this from closed to todo Oct 8, 2018
Sprint pycon-fr 2018 automation moved this from todo to closed Oct 8, 2018
@abnerh69
Copy link

New testing "Add a color to the background of a custom layouts rule/class" from [https://kivy.org/doc/stable/guide/widgets.html] but same problem:

[ERROR  ] [Loader      ] Failed to load image <http://www.everythingzoomer.com/wp-content/uploads/2013/01/Monday-joke-289x277.jpg>
Traceback (most recent call last):
  File "/Applications/Kivy3.app/Contents/Resources/venv/lib/python3.6/site-packages/kivy/loader.py", line 342, in _load_urllib
    fd = opener.open(request)
  File "/Applications/Kivy3.app/Contents/Frameworks/python/3.6.5/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/Applications/Kivy3.app/Contents/Frameworks/python/3.6.5/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Applications/Kivy3.app/Contents/Frameworks/python/3.6.5/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/Applications/Kivy3.app/Contents/Frameworks/python/3.6.5/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Applications/Kivy3.app/Contents/Frameworks/python/3.6.5/lib/python3.6/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

What am I doing wrong? What am I missing? (Note: Just copy/paste code from site)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

4 participants