Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 841: character maps to <undefined>
### INFO
**Python Version**: `2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]`
**Operating System**: `Windows-10-10.0.15063`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.8`
**Commit**: pymedusa/Medusa@a24f84c461fcecdca10bce6cf00bb54fc2c2d94a
**Link to Log**: https://gist.github.com/905d01c5dc50711592e4b0ec0c95de8e
### ERROR
<pre>
2017-08-12 08:47:17 ERROR    SEARCHQUEUE-FORCED-292745 :: [a24f84c] uTorrent: Unknown exception raised when send torrent to uTorrent : 'charmap' codec can't decode byte 0x8d in position 841: character maps to <undefined>
Traceback (most recent call last):
  File "C:\Medusa\medusa\clients\torrent\generic.py", line 79, in _request
    cookies=cookies, timeout=120, verify=False)
  File "C:\Medusa\lib\requests\sessions.py", line 518, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "C:\Medusa\lib\requests\sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Medusa\lib\requests\sessions.py", line 591, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "C:\Medusa\lib\requests\hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "C:\Medusa\medusa\session\hooks.py", line 28, in log_url
    log.debug('With post data: {data}'.format(data=resp.request.body))
  File "C:\Python27\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 841: character maps to <undefined>
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


Discussion:
with a warning 2017-08-12 08:47:17 WARNING  SEARCHQUEUE-FORCED-292745 :: [a24f84c] uTorrent: Unable to send Torrent ..  but it did actually send the torrent
This is only with torrenting.com when it sends a torrent to utorrent.
### INFO
**Python Version**: `2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]`
**Operating System**: `Windows-10-10.0.15063`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.8`
**Commit**: pymedusa/Medusa@1d0d7ea39cddd8b0a40f0dcec26dfa2eeac724fd
**Link to Log**: https://gist.github.com/8c035ca22f77d40a9e727ae49a7e274d
### ERROR
<pre>
2017-09-06 22:37:07 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [1d0d7ea] uTorrent: Unknown exception raised when send torrent to uTorrent : 'charmap' codec can't decode byte 0x8d in position 864: character maps to <undefined>
Traceback (most recent call last):
  File "C:\Medusa\medusa\clients\torrent\generic.py", line 79, in _request
    cookies=cookies, timeout=120, verify=False)
  File "C:\Medusa\lib\requests\sessions.py", line 518, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "C:\Medusa\lib\requests\sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Medusa\lib\requests\sessions.py", line 591, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "C:\Medusa\lib\requests\hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "C:\Medusa\medusa\session\hooks.py", line 28, in log_url
    log.debug('With post data: {data}'.format(data=resp.request.body))
  File "C:\Python27\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 864: character maps to <undefined>
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators
### INFO
**Python Version**: `2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]`
**Operating System**: `Windows-10-10.0.15063`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.8`
**Commit**: pymedusa/Medusa@1d0d7ea39cddd8b0a40f0dcec26dfa2eeac724fd
**Link to Log**: https://gist.github.com/138114fa0be49399f7f9c883cb8b52dd
### ERROR
<pre>
2017-09-06 22:37:03 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [1d0d7ea] uTorrent: Unknown exception raised when send torrent to uTorrent : 'charmap' codec can't decode byte 0x9d in position 850: character maps to <undefined>
Traceback (most recent call last):
  File "C:\Medusa\medusa\clients\torrent\generic.py", line 79, in _request
    cookies=cookies, timeout=120, verify=False)
  File "C:\Medusa\lib\requests\sessions.py", line 518, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "C:\Medusa\lib\requests\sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Medusa\lib\requests\sessions.py", line 591, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "C:\Medusa\lib\requests\hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "C:\Medusa\medusa\session\hooks.py", line 28, in log_url
    log.debug('With post data: {data}'.format(data=resp.request.body))
  File "C:\Python27\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 850: character maps to <undefined>
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators
### INFO
**Python Version**: `2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]`
**Operating System**: `Windows-10-10.0.15063`
**Locale**: `cp1252`
**Branch**: [develop](../tree/develop)
**Database**: `44.8`
**Commit**: pymedusa/Medusa@1d0d7ea39cddd8b0a40f0dcec26dfa2eeac724fd
**Link to Log**: https://gist.github.com/06452af27a32f66ca3430fcde28df10e
### ERROR
<pre>
2017-09-06 22:37:01 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [1d0d7ea] uTorrent: Unknown exception raised when send torrent to uTorrent : 'charmap' codec can't decode byte 0x8d in position 846: character maps to <undefined>
Traceback (most recent call last):
  File "C:\Medusa\medusa\clients\torrent\generic.py", line 79, in _request
    cookies=cookies, timeout=120, verify=False)
  File "C:\Medusa\lib\requests\sessions.py", line 518, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "C:\Medusa\lib\requests\sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Medusa\lib\requests\sessions.py", line 591, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "C:\Medusa\lib\requests\hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "C:\Medusa\medusa\session\hooks.py", line 28, in log_url
    log.debug('With post data: {data}'.format(data=resp.request.body))
  File "C:\Python27\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 846: character maps to <undefined>
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators
I am seeing this error with qbittorrent as well:
<pre>2017-09-08 00:54:45 ERROR    SEARCHQUEUE-DAILY-SEARCH :: [3f23fd2] qbittorrent: Unknown exception raised when send torrent to qbittorrent : 'charmap' codec can't decode byte 0x8d in position 897: character maps to <undefined>
Traceback (most recent call last):
  File "C:\SickRage\medusa\clients\torrent\generic.py", line 79, in _request
    cookies=cookies, timeout=120, verify=False)
  File "C:\SickRage\lib\requests\sessions.py", line 518, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "C:\SickRage\lib\requests\sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\SickRage\lib\requests\sessions.py", line 591, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "C:\SickRage\lib\requests\hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "C:\SickRage\medusa\session\hooks.py", line 28, in log_url
    log.debug('With post data: {data}'.format(data=resp.request.body))
  File "C:\Python27\lib\encodings\cp1252.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 897: character maps to <undefined></pre>

EDIT: Format spelling
This happens because the string is a byte-string encoded in `utf-8` but it's trying to decode it to native unicode using your system encoding (which is `cp1252` for you on windows).
so how do we fix it?



On Fri, Sep 8, 2017 at 1:36 PM, Labrys of Knossos <notifications@github.com>
wrote:

> This happens because the string is a byte-string encoded in utf-8 but
> it's trying to decode it to native unicode using your system encoding
> (which is cp1252 for you on windows).
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pymedusa/Medusa/issues/3004#issuecomment-328167661>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AGtVv-49mSabZFMk0vYu3BHcJT_gzkbUks5sgXs2gaJpZM4O1aAL>
> .
>

Lol.. its something that has to be fixed in code... I'm prepping for the hurricane right now so don't have time to fix it right now.  A quick "fix" would be to disable the logging of the post data in the `log_url` hook by commenting out line 28 in `medusa\session\hooks.py`.  A real fix may be as simple as decoding the `resp.request.body` with `utf-8` by changing line 28 to:

```python
log.debug('With post data: {data}'.format(data=resp.request.body.decode('utf-8')))
```


Resolving patch:
diff --git a/medusa/providers/generic_provider.py b/medusa/providers/generic_provider.py
--- a/medusa/providers/generic_provider.py
+++ b/medusa/providers/generic_provider.py
@@ -454,7 +454,8 @@ def get_url_hook(response, **kwargs):
         log.debug('{0} URL: {1} [Status: {2}]', response.request.method, response.request.url, response.status_code)
 
         if response.request.method == 'POST':
-            log.debug('With post data: {0}', response.request.body)
+            data = response.request.body.decode('utf-8')
+            log.debug('With post data: {0}', data)
 
     def get_url(self, url, post_data=None, params=None, timeout=30, **kwargs):
         """Load the given URL."""
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
@@ -1831,7 +1831,7 @@ def updateKODI(self, show=None):
         else:
             host = app.KODI_HOST
 
-        if notifiers.kodi_notifier.update_library(showName=show_name):
+        if notifiers.kodi_notifier.update_library(series_name=show_name):
             ui.notifications.message('Library update command sent to KODI host(s): {host}'.format(host=host))
         else:
             ui.notifications.error('Unable to contact one or more KODI host(s): {host}'.format(host=host))
diff --git a/medusa/session/hooks.py b/medusa/session/hooks.py
--- a/medusa/session/hooks.py
+++ b/medusa/session/hooks.py
@@ -25,7 +25,8 @@ def log_url(resp, **kwargs):
     log.debug('User-Agent: {}'.format(resp.request.headers['User-Agent']))
 
     if resp.request.method.upper() == 'POST':
-        log.debug('With post data: {data}'.format(data=resp.request.body))
+        data = resp.request.body.decode('utf-8')
+        log.debug('With post data: {data}'.format(data=data))
 
     return resp
 


Test patch: