Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: BraceException: Result text from SAB: {0}

### INFO
**Python Version**: `2.7.9 (default, Sep 26 2018, 05:58:52) [GCC 4.9.2]`
**Operating System**: `Linux-4.9.35-v7+-armv7l-with-debian-8.0`
**Locale**: `UTF-8`
**Branch**: [feature/fix-sub-enc-dec](../tree/feature/fix-sub-enc-dec)
**Database**: `44.12`
**Commit**: pymedusa/Medusa@4f826de5bbc43de6727a666c0953fa7043798927
**Link to Log**: https://gist.github.com/747d9fce9d8a8b3e22333f2eda0684c5
### ERROR
<pre>
2018-10-08 13:36:49 ERROR    SNATCHQUEUE-MANUALSNATCH-75682 :: [4f826de] BraceMessage string formatting failed. Using representation instead.
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/4f826de5bbc43de6727a666c0953fa7043798927/medusa/logger/adapters/style.py#L46">medusa/logger/adapters/style.py</a>", line 46, in __str__
    return self.msg.format(**kwargs)
IndexError: tuple index out of range
Traceback (most recent call last):
  File "/home/pi/Medusa/<a href="../blob/4f826de5bbc43de6727a666c0953fa7043798927/medusa/logger/adapters/style.py#L60">medusa/logger/adapters/style.py</a>", line 60, in __str__
    raise BraceException(self.msg)
BraceException: Result text from SAB: {0}
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:
This your department @medariox ? 😆
This is an easy fix. Will add it to that branch ASAP.
Fixed in https://github.com/pymedusa/Medusa/pull/5343

### INFO
**Python Version**: `2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]`
**Operating System**: `Linux-4.9.0-4-amd64-x86_64-with-debian-9.2`
**Locale**: `UTF-8`
**Branch**: [develop](../tree/develop)
**Database**: `44.12`
**Commit**: pymedusa/Medusa@a060ef18a8efcb315ceeca82e6d681d730528937
**Link to Log**: https://gist.github.com/ae364a2f22b9f7936be8007a9ae39584
### ERROR
<pre>
2018-10-10 04:57:43 ERROR    SNATCHQUEUE-MANUALSNATCH-331753 :: [a060ef1] BraceMessage string formatting failed. Using representation instead.
Traceback (most recent call last):
  File "/opt/medusa/<a href="../blob/a060ef18a8efcb315ceeca82e6d681d730528937/medusa/logger/adapters/style.py#L46">medusa/logger/adapters/style.py</a>", line 46, in __str__
    return self.msg.format(**kwargs)
IndexError: tuple index out of range
Traceback (most recent call last):
  File "/opt/medusa/<a href="../blob/a060ef18a8efcb315ceeca82e6d681d730528937/medusa/logger/adapters/style.py#L60">medusa/logger/adapters/style.py</a>", line 60, in __str__
    raise BraceException(self.msg)
BraceException: Result text from SAB: {0}
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators

Looks like I need to debug this properly.

Resolving patch:
diff --git a/medusa/clients/nzb/sab.py b/medusa/clients/nzb/sab.py
--- a/medusa/clients/nzb/sab.py
+++ b/medusa/clients/nzb/sab.py
@@ -10,6 +10,7 @@
 from __future__ import unicode_literals
 
 import datetime
+import json
 import logging
 
 from medusa import app
@@ -127,12 +128,14 @@ def _check_sab_response(jdata):
     """
     error = jdata.get('error')
 
-    if error == 'API Key Incorrect':
+    if error == 'API Key Required':
+        log.warning("Sabnzbd's API key is missing")
+    elif error == 'API Key Incorrect':
         log.warning("Sabnzbd's API key is incorrect")
     elif error:
         log.error('Sabnzbd encountered an error: {0}', error)
 
-    return not error, error or jdata
+    return not error, error or json.dumps(jdata)
 
 
 def get_sab_access_method(host=None):
@@ -178,5 +181,5 @@ def test_authentication(host=None, username=None, password=None, apikey=None):
         log.info('Error connecting to sab, no data returned')
     else:
         # check the result and determine if it's good or not
-        result, sab_text = _check_sab_response(data)
-        return result, 'success' if result else sab_text
+        result, text = _check_sab_response(data)
+        return result, 'success' if result else text
diff --git a/medusa/server/web/home/handler.py b/medusa/server/web/home/handler.py
--- a/medusa/server/web/home/handler.py
+++ b/medusa/server/web/home/handler.py
@@ -293,7 +293,7 @@ def testSABnzbd(host=None, username=None, password=None, apikey=None):
             if authed:
                 return 'Success. Connected and authenticated'
             else:
-                return 'Authentication failed. SABnzbd expects {access!r} as authentication method, {auth!r}'.format(
+                return 'Authentication failed. SABnzbd expects {access!r} as authentication method, {auth}'.format(
                     access=acces_msg, auth=auth_msg)
         else:
             return 'Unable to connect to host'


Test patch: