2

I'm trying to display image in kivy application, but image loader returns error 403 forbidden.

I noticed that I have to send User-Agent header to bypass this error, but i couldn't find any way to pass headers to image loader

Is there any way to solve this problem?

kv file

AsyncImage:
    source: 'url_to_image'
    keep_ratio: True

error:

[ERROR  ] [Loader      ] Failed to load image <url_to_image>
urllib.error.HTTPError: HTTP Error 403: Forbidden
4

1 回答 1

1

Currently you can't modify the User-Agent when using AsyncImage. The responsible code is here:

fd = urllib_request.urlopen(filename)

As you see there is no good way to pass a different UserAgent in there.

Instead handle the download of the file yourself.

I guess you could also try to pass an urllib.request.Request object with a modified split method so that the variable filename does not actually contain a string but a Request, but still survives the checks of StringProperty (in AsyncImage). But that would probably be very unstable and not a "proper" solution.

于 2016-09-21T07:37:39.047 回答