Repository: pymedusa/Medusa

Issue:
Emby notifications not working

Branch: master
Commit: 7cfc79d5280b719c6288090fb805521dfc0402cd
Version: v0.2.6
Database: 44.11
Python Version: | 2.7.9 (default, Aug 13 2016, 17:56:53) [GCC 4.9.2]
SSL Version: | OpenSSL 1.0.1t 3 May 2016
OS: | Linux-4.9.61+-armv7l-with-debian-8.11
Locale: | en_GB.UTF-8

I haven't changed the IP, port or API of the Emby device but notifications no longer work. 

This is in the log:
```
2018-07-05 22:43:11 WARNING  Thread_34 :: [7cfc79d] EMBY: Warning: Unable to contact Emby at http://**********/emby/Notifications/Admin: 500 Server Error: Internal Server Error for url: http://**********/emby/Notifications/Admin
```

I think this has just started with the most recent update of Medusa. There haven't been any Emby updates for a couple of weeks. Restarting Emby - no difference. 

Restated Medusa and it updated to:

Branch: master
Commit: e7c4ff3bc9a48b47c932b0e40a539d62e3a62f64
Version: v0.2.6
Database: 44.11
Python Version: | 2.7.9 (default, Aug 13 2016, 17:56:53) [GCC 4.9.2]
SSL Version: | OpenSSL 1.0.1t 3 May 2016
OS: | Linux-4.9.61+-armv7l-with-debian-8.11
Locale: | en_GB.UTF-8

But the problem persists.

Thanks for checking out.



Discussion:
@johnvick 
Did you change the `Admin` username on Emby?
No, haven't changed any Emby settings (other than changing the API but this was after the problem arose - but this didn't help).
I need to look into this more, because I don't have Emby installed to check that.

In any case, that's just the notification test. It **should** still work for updating the library from Medusa.
If all the other settings for Emby are correct, of course.
It doesn't trigger the Emby library update as it did before when you click the Emby update button on the TV series screen. Emby is otherwise working fine  as is the Emby/Kodi plugin setup over multiple devices around the house.
Please check the Emby logs. I can't reproduce this error.

Resolving patch:
diff --git a/medusa/notifiers/emby.py b/medusa/notifiers/emby.py
--- a/medusa/notifiers/emby.py
+++ b/medusa/notifiers/emby.py
@@ -3,6 +3,7 @@
 """Emby notifier module."""
 from __future__ import unicode_literals
 
+import json
 import logging
 
 from medusa import app
@@ -14,7 +15,7 @@
 
 from requests.exceptions import HTTPError, RequestException
 
-from six import text_type as str
+from six import text_type
 
 log = BraceAdapter(logging.getLogger(__name__))
 log.logger.addHandler(logging.NullHandler())
@@ -39,14 +40,15 @@ def _notify_emby(self, message, host=None, emby_apikey=None):
             emby_apikey = app.EMBY_APIKEY
 
         url = 'http://{host}/emby/Notifications/Admin'.format(host=host)
+        data = json.dumps({
+            'Name': 'Medusa',
+            'Description': message,
+            'ImageUrl': app.LOGO_URL
+        })
         try:
             resp = self.session.post(
                 url=url,
-                data={
-                    'Name': 'Medusa',
-                    'Description': message,
-                    'ImageUrl': app.LOGO_URL
-                },
+                data=data,
                 headers={
                     'X-MediaBrowser-Token': emby_apikey,
                     'Content-Type': 'application/json'
@@ -110,7 +112,7 @@ def update_library(self, show=None):
                     return False
 
                 params = {
-                    provider: str(tvdb_id)
+                    provider: text_type(tvdb_id)
                 }
             else:
                 params = {}


Test patch: