Skip to content

Instantly share code, notes, and snippets.

@hecanjog
Created Mar 2, 2022
Embed
What would you like to do?
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