Skip to content

Instantly share code, notes, and snippets.

@hecanjog
Created March 2, 2022 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hecanjog/0e8d39732f0beb11e93d3869d3c807f2 to your computer and use it in GitHub Desktop.
Save hecanjog/0e8d39732f0beb11e93d3869d3c807f2 to your computer and use it in GitHub Desktop.
403 example
import urllib.request
with urllib.request.urlopen('https://twtxt.net/user/prologic/twtxt.txt') as conn:
feed = conn.read().decode('utf-8')
print(feed)
(~) % python prologic.py                                                                                                                                              Wed 2 12:38PM  lake 
Traceback (most recent call last):
  File "/home/hecanjog/prologic.py", line 3, in <module>
    with urllib.request.urlopen('https://twtxt.net/user/prologic/twtxt.txt') as conn:
  File "/home/hecanjog/.pyenv/versions/3.9.9/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/home/hecanjog/.pyenv/versions/3.9.9/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/home/hecanjog/.pyenv/versions/3.9.9/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/home/hecanjog/.pyenv/versions/3.9.9/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  File "/home/hecanjog/.pyenv/versions/3.9.9/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/home/hecanjog/.pyenv/versions/3.9.9/lib/python3.9/urllib/request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
zsh: exit 1     python prologic.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment