Forums

Exception when opening jpg URL

Hi,

I'm developing an application that alters an image. It is written in pure python (no Django or other stuff). It doesn't even have a webpage. When I try to open an URL using urllib. I get the following exception:

  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/urllib/request.py", line 153, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.4/urllib/request.py", line 461, in open
    response = meth(req, response)
  File "/usr/lib/python3.4/urllib/request.py", line 571, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.4/urllib/request.py", line 499, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 579, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

I ran the following code:

import urllib.request
urllib.request.urlopen('http://i.imgur.com/ssztN.jpg')

Is there a restriction regarding loading image URLs on Pythonanywhere? This code works fine on my machine.

It turns out free accounts only have access to whitelisted sites. api.imgur.com is whitelisted, while imgur.com is not. I guess that's the problem.

Yup. That's exactly it.