403 Forbidden while trying to display image from url - Kivy
<p>I'm trying to display image in kivy application, but image loader returns error 403 forbidden.</p>

<p>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</p>

<p>Is there any way to solve this problem?</p>

<p>kv file</p>

<pre><code>AsyncImage:
    source: 'url_to_image'
    keep_ratio: True
</code></pre>

<p>error:</p>

<pre><code>[ERROR  ] [Loader      ] Failed to load image &lt;url_to_image&gt;
urllib.error.HTTPError: HTTP Error 403: Forbidden
</code></pre>

<p>Currently you can't modify the User-Agent when using AsyncImage. The responsible code is <a href="https://github.com/kivy/kivy/blob/master/kivy/loader.py#L317" rel="nofollow">here</a>:</p>

<pre><code>fd = urllib_request.urlopen(filename)
</code></pre>

<p>As you see there is no good way to pass a different UserAgent in there. </p>

<p>Instead handle the download of the file yourself.</p>

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

python kivy kivy-language