Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: AttributeError: 'NoneType' object has no attribute 'status_code'

### INFO
**Python Version**: `3.6.7 (default, Oct 21 2018, 08:08:16) [GCC 8.2.0]`
**Operating System**: `Linux-4.9.35-v7+-armv7l-with-debian-buster-sid`
**Locale**: `UTF-8`
**Branch**: [develop](../tree/develop)
**Database**: `44.13`
**Commit**: pymedusa/Medusa@6bd26ddf43bb8c7be86aab31e808bf06168f9b3c
**Link to Log**: https://gist.github.com/ac6e3791daa574c3331043d900e533e2
### ERROR
<pre>
2019-01-22 00:24:50 ERROR    SNATCHQUEUE-SNATCH-270633 :: [6bd26dd] Snatch failed! For result: True.Detective.S03E03.The.Big.Never.1080p.AMZN.WEB-DL.DDP5.1.H.264-NTb.mkv
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/connectionpool.py#L600">ext/urllib3/connectionpool.py</a>", line 600, in urlopen
    chunked=chunked)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/connectionpool.py#L343">ext/urllib3/connectionpool.py</a>", line 343, in _make_request
    self._validate_conn(conn)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/connectionpool.py#L839">ext/urllib3/connectionpool.py</a>", line 839, in _validate_conn
    conn.connect()
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/connection.py#L344">ext/urllib3/connection.py</a>", line 344, in connect
    ssl_context=context)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/util/ssl_.py#L344">ext/urllib3/util/ssl_.py</a>", line 344, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/usr/lib/python3.6/ssl.py", line 817, in __init__
    self.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
OSError: [Errno 0] Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/requests/adapters.py#L449">ext/requests/adapters.py</a>", line 449, in send
    timeout=timeout
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/connectionpool.py#L638">ext/urllib3/connectionpool.py</a>", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/util/retry.py#L367">ext/urllib3/util/retry.py</a>", line 367, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/packages/six.py#L685">ext/urllib3/packages/six.py</a>", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/connectionpool.py#L600">ext/urllib3/connectionpool.py</a>", line 600, in urlopen
    chunked=chunked)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/connectionpool.py#L343">ext/urllib3/connectionpool.py</a>", line 343, in _make_request
    self._validate_conn(conn)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/connectionpool.py#L839">ext/urllib3/connectionpool.py</a>", line 839, in _validate_conn
    conn.connect()
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/connection.py#L344">ext/urllib3/connection.py</a>", line 344, in connect
    ssl_context=context)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/urllib3/util/ssl_.py#L344">ext/urllib3/util/ssl_.py</a>", line 344, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/usr/lib/python3.6/ssl.py", line 817, in __init__
    self.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError(0, 'Error'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/notifiers/telegram.py#L65">medusa/notifiers/telegram.py</a>", line 65, in _send_telegram_msg
    r = requests.post(telegram_api.format(api_key=api_key), data=payload)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/requests/api.py#L116">ext/requests/api.py</a>", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/requests/api.py#L60">ext/requests/api.py</a>", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/requests/sessions.py#L533">ext/requests/sessions.py</a>", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/requests/sessions.py#L646">ext/requests/sessions.py</a>", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/ext/requests/adapters.py#L498">ext/requests/adapters.py</a>", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', OSError(0, 'Error'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/search/queue.py#L503">medusa/search/queue.py</a>", line 503, in run
    self.success = snatch_episode(result)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/search/core.py#L222">medusa/search/core.py</a>", line 222, in snatch_episode
    notifiers.notify_snatch(curEpObj, result)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/notifiers/__init__.py#L127">medusa/notifiers/__init__.py</a>", line 127, in notify_snatch
    n.notify_snatch(title, message)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/notifiers/telegram.py#L96">medusa/notifiers/telegram.py</a>", line 96, in notify_snatch
    self._notify_telegram(title, message)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/notifiers/telegram.py#L160">medusa/notifiers/telegram.py</a>", line 160, in _notify_telegram
    return self._send_telegram_msg(title, message, user_id, api_key)
  File "/home/pi/Medusa/<a href="../blob/6bd26ddf43bb8c7be86aab31e808bf06168f9b3c/medusa/notifiers/telegram.py#L78">medusa/notifiers/telegram.py</a>", line 78, in _send_telegram_msg
    if error.response.status_code in error_message:
AttributeError: 'NoneType' object has no attribute 'status_code'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:

Resolving patch:
diff --git a/medusa/notifiers/telegram.py b/medusa/notifiers/telegram.py
--- a/medusa/notifiers/telegram.py
+++ b/medusa/notifiers/telegram.py
@@ -68,7 +68,7 @@ def _send_telegram_msg(self, title, msg, user_id=None, api_key=None):
             success = True
         except RequestException as error:
             message = 'Unknown IO error: %s' % error
-            if hasattr(error, 'response'):
+            if hasattr(error, 'response') and error.response is not None:
                 error_message = {
                     400: 'Missing parameter(s). Double check your settings or if the channel/user exists.',
                     401: 'Authentication failed.',


Test patch: