Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import urllib.request
- jsonUrl = "https://gist.githubusercontent.com/planetoftheweb/98f35786733c8cccf81e/raw/f3dad774ed1fe20b36011b1261bb392ee759b867/data.json"
- with urllib.request.urlopen(jsonUrl) as response:
- data = json.loads(response.read())
- print(data)
- jsonUrl = "http://8ball.delegator.com/magic/JSON/blah"
- with urllib.request.urlopen(jsonUrl) as response:
- data = json.loads(response.read())
- print(data)
- error message
- Traceback (most recent call last):
- File "test.py", line 10, in <module>
- with urllib.request.urlopen(jsonUrl) as response:
- File "/usr/lib64/python3.6/urllib/request.py", line 223, in urlopen
- return opener.open(url, data, timeout)
- File "/usr/lib64/python3.6/urllib/request.py", line 532, in open
- response = meth(req, response)
- File "/usr/lib64/python3.6/urllib/request.py", line 642, in http_response
- 'http', request, response, code, msg, hdrs)
- File "/usr/lib64/python3.6/urllib/request.py", line 570, in error
- return self._call_chain(*args)
- File "/usr/lib64/python3.6/urllib/request.py", line 504, in _call_chain
- result = func(*args)
- File "/usr/lib64/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement