hrbonz/bonzbot

handle 403 and other error HTTP status codes [linkinfo]

hrbonz opened this issue · 0 comments

When opening https://engineering.upside.com/a-beginners-guide-to-optimizing-pandas-code-for-speed-c09ef2c6a4d6

ERROR asyncio    Exception in callback event.async_callback({'data': 'https://engi...-c09ef2c6a
4d6', 'event': 'PRIVMSG', 'mask': 'anhj!~anhj@l...2.litchis.org', 'target': '#bonz'})
handle: <Handle event.async_callback({'data': 'https://engi...-c09ef2c6a4d6', 'event': 'PRIVMSG
', 'mask': 'anhj!~anhj@l...2.litchis.org', 'target': '#bonz'})>
Traceback (most recent call last):
  File "/home/hr/codaz/bonzbot/bonzbot/linkinfo/__init__.py", line 41, in get_title
    soup = bs4.BeautifulSoup(urlopen(req, timeout=5), "lxml")
  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 493, in error
    result = 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 676, in http_error_302
    return self.parent.open(new, timeout=req.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

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/events.py", line 120, in _run
    self._callback(*self._args)
  File "/home/hr/.virtualenvs/bonzbot3/lib/python3.4/site-packages/irc3/dec.py", line 54, in as
ync_callback
    return self.callback(**kwargs)
  File "/home/hr/codaz/bonzbot/bonzbot/linkinfo/__init__.py", line 68, in getlink
    info = self.get_info(link)
  File "/home/hr/codaz/bonzbot/bonzbot/linkinfo/__init__.py", line 58, in get_info
    return _handler(match)
  File "/home/hr/codaz/bonzbot/bonzbot/linkinfo/__init__.py", line 42, in get_title
    except urllib2.HTTPError as e:
NameError: name 'urllib2' is not defined