Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: error: [Errno 99] Address not available

### INFO
**Python Version**: `2.7.14 (default, Dec 14 2017, 15:51:29) [GCC 6.4.0]`
**Operating System**: `Linux-4.2.8-x86_64-with`
**Locale**: `None`
**Branch**: [master](../tree/master)
**Database**: `44.11`
**Commit**: pymedusa/Medusa@c65ca2607fae74405dcceaaf8c02f3d29d0313ea
**Link to Log**: https://gist.github.com/0d062813555bacfdadcc7bbfcf7c7e28
### ERROR
<pre>
2018-06-11 14:32:43 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [c65ca26] DailySearchQueueItem Exception, error: [Errno 99] Address not available
Traceback (most recent call last):
  File "/app/medusa/medusa/search/queue.py", line 289, in run
    self.success = snatch_episode(result)
  File "/app/medusa/medusa/search/core.py", line 147, in snatch_episode
    result_downloaded = **********.sendNZB(result, is_proper)
  File "/app/medusa/medusa/clients/nzb/**********.py", line 92, in sendNZB
    if not NZBConnection(url):
  File "/app/medusa/medusa/clients/nzb/**********.py", line 29, in NZBConnection
    if nzbGetRPC.writelog('INFO', 'Medusa connected to test connection.'):
  File "/usr/lib/python2.7/xmlrpclib.py", line 1243, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1602, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1283, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1311, in single_request
    self.send_content(h, request_body)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1459, in send_content
    connection.endheaders(request_body)
  File "/usr/lib/python2.7/httplib.py", line 1038, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 882, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 844, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 821, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 575, in create_connection
    raise err
error: [Errno 99] Address not available
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:

### INFO
**Python Version**: `2.7.14 (default, Dec 14 2017, 15:51:29) [GCC 6.4.0]`
**Operating System**: `Linux-4.2.8-x86_64-with`
**Locale**: `None`
**Branch**: [master](../tree/master)
**Database**: `44.11`
**Commit**: pymedusa/Medusa@c65ca2607fae74405dcceaaf8c02f3d29d0313ea
**Link to Log**: https://gist.github.com/b3fbb88dadd3f691c7a97bd2d3c495bf
### ERROR
<pre>
2018-06-11 15:16:18 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [c65ca26] DailySearchQueueItem Exception, error: [Errno 99] Address not available
Traceback (most recent call last):
  File "/app/medusa/medusa/search/queue.py", line 289, in run
    self.success = snatch_episode(result)
  File "/app/medusa/medusa/search/core.py", line 147, in snatch_episode
    result_downloaded = **********.sendNZB(result, is_proper)
  File "/app/medusa/medusa/clients/nzb/**********.py", line 92, in sendNZB
    if not NZBConnection(url):
  File "/app/medusa/medusa/clients/nzb/**********.py", line 29, in NZBConnection
    if nzbGetRPC.writelog('INFO', 'Medusa connected to test connection.'):
  File "/usr/lib/python2.7/xmlrpclib.py", line 1243, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1602, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1283, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1311, in single_request
    self.send_content(h, request_body)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1459, in send_content
    connection.endheaders(request_body)
  File "/usr/lib/python2.7/httplib.py", line 1038, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 882, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 844, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 821, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 575, in create_connection
    raise err
error: [Errno 99] Address not available
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators

Your NZB client wasn't reachable, should be handled gracefully tho.

Resolving patch:
diff --git a/medusa/clients/nzb/nzbget.py b/medusa/clients/nzb/nzbget.py
--- a/medusa/clients/nzb/nzbget.py
+++ b/medusa/clients/nzb/nzbget.py
@@ -4,6 +4,7 @@
 
 import datetime
 import logging
+import socket
 from base64 import standard_b64encode
 from xmlrpc.client import Error, ProtocolError, ServerProxy
 
@@ -41,11 +42,17 @@ def NZBConnection(url):
         return False
 
     except Error as error:
-        log.warning('Please check your NZBget host and port (if it is'
-                    ' running). NZBget is not responding to this combination'
+        log.warning('Please check your NZBget host and port (if it is running).'
+                    ' NZBget is not responding to this combination.'
                     ' Error: {msg}', {'msg': error.errmsg})
         return False
 
+    except socket.error as error:
+        log.warning('Please check your NZBget host and port (if it is running).'
+                    ' NZBget is not responding to this combination.'
+                    ' Socket Error: {msg}', {'msg': error})
+        return False
+
 
 def testNZB(host, username, password, use_https):
     """Test NZBget client connection.


Test patch: