We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[APP SUBMITTED]: TypeError: a bytes-like object is required, not 'str'

### INFO
**Python Version**: `3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516]`
**Operating System**: `Linux-4.9.0-4-amd64-x86_64-with-debian-9.6`
**Locale**: `UTF-8`
**Branch**: [feature/py3_2](../tree/feature/py3_2)
**Database**: `44.12`
**Commit**: pymedusa/Medusa@ac61f7ad628d70528cab9e8971071d79c0e90a95
**Link to Log**: https://gist.github.com/ee3a4c1fb32f4ed87dc90f4360ceba99
### ERROR
<pre>
2018-12-03 07:31:45 ERROR    SNATCHQUEUE-SNATCH-114801 :: [ac61f7a] Snatch failed! For result: [HorribleSubs].Fairy.Tail.Final.Season.-.286.[1080p].mkv
Traceback (most recent call last):
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/medusa/search/queue.py#L502">medusa/search/queue.py</a>", line 502, in run
    self.success = snatch_episode(result)
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/medusa/search/core.py#L167">medusa/search/core.py</a>", line 167, in snatch_episode
    result_downloaded = client.send_torrent(result)
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/medusa/clients/torrent/generic.py#L246">medusa/clients/torrent/generic.py</a>", line 246, in send_torrent
    if not self._get_auth():
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/medusa/clients/torrent/rtorrent_client.py#L55">medusa/clients/torrent/rtorrent_client.py</a>", line 55, in _get_auth
    self.auth = RTorrent(self.host, None, None, True)
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/__init__.py#L87">lib/rtorrent/__init__.py</a>", line 87, in __init__
    self._verify_conn()
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/__init__.py#L126">lib/rtorrent/__init__.py</a>", line 126, in _verify_conn
    assert 'system.client_version' in self._get_rpc_methods(
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/__init__.py#L164">lib/rtorrent/__init__.py</a>", line 164, in _get_rpc_methods
    return(self._rpc_methods or self._update_rpc_methods())
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/__init__.py#L154">lib/rtorrent/__init__.py</a>", line 154, in _update_rpc_methods
    self._rpc_methods = self._get_conn().system.listMethods()
  File "/usr/lib/python3.5/xmlrpc/client.py", line 1092, in __call__
    return self.__send(self.__name, args)
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/lib/xmlrpc/scgi.py#L195">lib/rtorrent/lib/xmlrpc/scgi.py</a>", line 195, in __request
    verbose=self.__verbose
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/lib/xmlrpc/scgi.py#L104">lib/rtorrent/lib/xmlrpc/scgi.py</a>", line 104, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/opt/medusa/<a href="../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/lib/xmlrpc/scgi.py#L135">lib/rtorrent/lib/xmlrpc/scgi.py</a>", line 135, in single_request
    sock.send(request_body)
TypeError: a bytes-like object is required, not 'str'
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `medusa/session/hooks.py`
Content:
```
1 # coding=utf-8
2 
3 from __future__ import unicode_literals
4 
5 import logging
6 
7 from medusa.logger.adapters.style import BraceAdapter
8 
9 from six import text_type
10 
11 log = BraceAdapter(logging.getLogger(__name__))
12 log.logger.addHandler(logging.NullHandler())
13 
14 
15 def log_url(response, **kwargs):
16     """Response hook to log request URL."""
17     request = response.request
18     log.debug(
19         '{method} URL: {url} [Status: {status}]', {
20             'method': request.method,
21             'url': request.url,
22             'status': response.status_code,
23         }
24     )
25     log.debug('User-Agent: {}'.format(request.headers['User-Agent']))
26 
27     if request.method.upper() == 'POST':
28         if request.body:
29             if 'multipart/form-data' not in request.headers.get('content-type', ''):
30                 body = request.body
31             else:
32                 body = request.body[1:99].replace('\n', ' ') + '...'
33         else:
34             body = ''
35 
36         # try to log post data using various codecs to decode
37         if isinstance(body, text_type):
38             log.debug('With post data: {0}', body)
39             return
40 
41         codecs = ('utf-8', 'latin1', 'cp1252')
42         for codec in codecs:
43             try:
44                 data = body.decode(codec)
45             except UnicodeError as error:
46                 log.debug('Failed to decode post data as {codec}: {msg}',
47                           {'codec': codec, 'msg': error})
48             else:
49                 log.debug('With post data: {0}', data)
50                 break
51         else:
52             log.warning('Failed to decode post data with {codecs}',
53                         {'codecs': codecs})
54
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/medusa/session/hooks.py b/medusa/session/hooks.py
--- a/medusa/session/hooks.py
+++ b/medusa/session/hooks.py
@@ -6,7 +6,7 @@
 
 from medusa.logger.adapters.style import BraceAdapter
 
-from six import text_type
+from six import ensure_text
 
 log = BraceAdapter(logging.getLogger(__name__))
 log.logger.addHandler(logging.NullHandler())
@@ -26,28 +26,12 @@
 
     if request.method.upper() == 'POST':
         if request.body:
+            text_body = ensure_text(request.body)
             if 'multipart/form-data' not in request.headers.get('content-type', ''):
-                body = request.body
+                body = text_body
+            elif len(text_body) > 99:
+                body = text_body[0:99].replace('\n', ' ') + '...'
             else:
-                body = request.body[1:99].replace('\n', ' ') + '...'
-        else:
-            body = ''
+                body = text_body.replace('\n', ' ')
 
-        # try to log post data using various codecs to decode
-        if isinstance(body, text_type):
             log.debug('With post data: {0}', body)
-            return
-
-        codecs = ('utf-8', 'latin1', 'cp1252')
-        for codec in codecs:
-            try:
-                data = body.decode(codec)
-            except UnicodeError as error:
-                log.debug('Failed to decode post data as {codec}: {msg}',
-                          {'codec': codec, 'msg': error})
-            else:
-                log.debug('With post data: {0}', data)
-                break
-        else:
-            log.warning('Failed to decode post data with {codecs}',
-                        {'codecs': codecs})

{"golden_diff": "diff --git a/medusa/session/hooks.py b/medusa/session/hooks.py\n--- a/medusa/session/hooks.py\n+++ b/medusa/session/hooks.py\n@@ -6,7 +6,7 @@\n \n from medusa.logger.adapters.style import BraceAdapter\n \n-from six import text_type\n+from six import ensure_text\n \n log = BraceAdapter(logging.getLogger(__name__))\n log.logger.addHandler(logging.NullHandler())\n@@ -26,28 +26,12 @@\n \n     if request.method.upper() == 'POST':\n         if request.body:\n+            text_body = ensure_text(request.body)\n             if 'multipart/form-data' not in request.headers.get('content-type', ''):\n-                body = request.body\n+                body = text_body\n+            elif len(text_body) > 99:\n+                body = text_body[0:99].replace('\\n', ' ') + '...'\n             else:\n-                body = request.body[1:99].replace('\\n', ' ') + '...'\n-        else:\n-            body = ''\n+                body = text_body.replace('\\n', ' ')\n \n-        # try to log post data using various codecs to decode\n-        if isinstance(body, text_type):\n             log.debug('With post data: {0}', body)\n-            return\n-\n-        codecs = ('utf-8', 'latin1', 'cp1252')\n-        for codec in codecs:\n-            try:\n-                data = body.decode(codec)\n-            except UnicodeError as error:\n-                log.debug('Failed to decode post data as {codec}: {msg}',\n-                          {'codec': codec, 'msg': error})\n-            else:\n-                log.debug('With post data: {0}', data)\n-                break\n-        else:\n-            log.warning('Failed to decode post data with {codecs}',\n-                        {'codecs': codecs})\n", "issue": "[APP SUBMITTED]: TypeError: a bytes-like object is required, not 'str'\n\n### INFO\n**Python Version**: `3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516]`\n**Operating System**: `Linux-4.9.0-4-amd64-x86_64-with-debian-9.6`\n**Locale**: `UTF-8`\n**Branch**: [feature/py3_2](../tree/feature/py3_2)\n**Database**: `44.12`\n**Commit**: pymedusa/Medusa@ac61f7ad628d70528cab9e8971071d79c0e90a95\n**Link to Log**: https://gist.github.com/ee3a4c1fb32f4ed87dc90f4360ceba99\n### ERROR\n<pre>\n2018-12-03 07:31:45 ERROR    SNATCHQUEUE-SNATCH-114801 :: [ac61f7a] Snatch failed! For result: [HorribleSubs].Fairy.Tail.Final.Season.-.286.[1080p].mkv\nTraceback (most recent call last):\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/medusa/search/queue.py#L502\">medusa/search/queue.py</a>\", line 502, in run\n    self.success = snatch_episode(result)\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/medusa/search/core.py#L167\">medusa/search/core.py</a>\", line 167, in snatch_episode\n    result_downloaded = client.send_torrent(result)\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/medusa/clients/torrent/generic.py#L246\">medusa/clients/torrent/generic.py</a>\", line 246, in send_torrent\n    if not self._get_auth():\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/medusa/clients/torrent/rtorrent_client.py#L55\">medusa/clients/torrent/rtorrent_client.py</a>\", line 55, in _get_auth\n    self.auth = RTorrent(self.host, None, None, True)\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/__init__.py#L87\">lib/rtorrent/__init__.py</a>\", line 87, in __init__\n    self._verify_conn()\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/__init__.py#L126\">lib/rtorrent/__init__.py</a>\", line 126, in _verify_conn\n    assert 'system.client_version' in self._get_rpc_methods(\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/__init__.py#L164\">lib/rtorrent/__init__.py</a>\", line 164, in _get_rpc_methods\n    return(self._rpc_methods or self._update_rpc_methods())\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/__init__.py#L154\">lib/rtorrent/__init__.py</a>\", line 154, in _update_rpc_methods\n    self._rpc_methods = self._get_conn().system.listMethods()\n  File \"/usr/lib/python3.5/xmlrpc/client.py\", line 1092, in __call__\n    return self.__send(self.__name, args)\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/lib/xmlrpc/scgi.py#L195\">lib/rtorrent/lib/xmlrpc/scgi.py</a>\", line 195, in __request\n    verbose=self.__verbose\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/lib/xmlrpc/scgi.py#L104\">lib/rtorrent/lib/xmlrpc/scgi.py</a>\", line 104, in request\n    return self.single_request(host, handler, request_body, verbose)\n  File \"/opt/medusa/<a href=\"../blob/ac61f7ad628d70528cab9e8971071d79c0e90a95/lib/rtorrent/lib/xmlrpc/scgi.py#L135\">lib/rtorrent/lib/xmlrpc/scgi.py</a>\", line 135, in single_request\n    sock.send(request_body)\nTypeError: a bytes-like object is required, not 'str'\n</pre>\n---\n_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators\n\n", "before_files": [{"content": "# coding=utf-8\n\nfrom __future__ import unicode_literals\n\nimport logging\n\nfrom medusa.logger.adapters.style import BraceAdapter\n\nfrom six import text_type\n\nlog = BraceAdapter(logging.getLogger(__name__))\nlog.logger.addHandler(logging.NullHandler())\n\n\ndef log_url(response, **kwargs):\n    \"\"\"Response hook to log request URL.\"\"\"\n    request = response.request\n    log.debug(\n        '{method} URL: {url} [Status: {status}]', {\n            'method': request.method,\n            'url': request.url,\n            'status': response.status_code,\n        }\n    )\n    log.debug('User-Agent: {}'.format(request.headers['User-Agent']))\n\n    if request.method.upper() == 'POST':\n        if request.body:\n            if 'multipart/form-data' not in request.headers.get('content-type', ''):\n                body = request.body\n            else:\n                body = request.body[1:99].replace('\\n', ' ') + '...'\n        else:\n            body = ''\n\n        # try to log post data using various codecs to decode\n        if isinstance(body, text_type):\n            log.debug('With post data: {0}', body)\n            return\n\n        codecs = ('utf-8', 'latin1', 'cp1252')\n        for codec in codecs:\n            try:\n                data = body.decode(codec)\n            except UnicodeError as error:\n                log.debug('Failed to decode post data as {codec}: {msg}',\n                          {'codec': codec, 'msg': error})\n            else:\n                log.debug('With post data: {0}', data)\n                break\n        else:\n            log.warning('Failed to decode post data with {codecs}',\n                        {'codecs': codecs})\n", "path": "medusa/session/hooks.py"}], "after_files": [{"content": "# coding=utf-8\n\nfrom __future__ import unicode_literals\n\nimport logging\n\nfrom medusa.logger.adapters.style import BraceAdapter\n\nfrom six import ensure_text\n\nlog = BraceAdapter(logging.getLogger(__name__))\nlog.logger.addHandler(logging.NullHandler())\n\n\ndef log_url(response, **kwargs):\n    \"\"\"Response hook to log request URL.\"\"\"\n    request = response.request\n    log.debug(\n        '{method} URL: {url} [Status: {status}]', {\n            'method': request.method,\n            'url': request.url,\n            'status': response.status_code,\n        }\n    )\n    log.debug('User-Agent: {}'.format(request.headers['User-Agent']))\n\n    if request.method.upper() == 'POST':\n        if request.body:\n            text_body = ensure_text(request.body)\n            if 'multipart/form-data' not in request.headers.get('content-type', ''):\n                body = text_body\n            elif len(text_body) > 99:\n                body = text_body[0:99].replace('\\n', ' ') + '...'\n            else:\n                body = text_body.replace('\\n', ' ')\n\n            log.debug('With post data: {0}', body)\n", "path": "medusa/session/hooks.py"}]}