Repository: pymedusa/Medusa

Issue:
Failed to send torrent to qBittorrent if theres an accent in the name
**Branch/Commit:** develop
**OS:** Windows 10

I'm developing an new provider (BJ-Share) and after many tests i discovered that if the torrent name include accents, i receive the telegram message just fine saying about the download, but its not added to qbittorrent. if i remove the accents from the torrent name, it download just fine.

I tested with Black Hole and the torrent was saved fine, even with accents, so must be some problem in the API Call to qBittorrent (i'm not sure if that happens to others torrent clients)

**Logs:**

That's the response from qbittorrent when i try to send an torrent with accent:

```2018-05-18 13:04:06 INFO     SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Beginning to manual snatch release: Black.Clover.-.S01E32.MKV./.H.264./.AAC./.HDTV./.Legendado./.Japonês./.1080p
2018-05-18 13:04:06 INFO     SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Downloading Black.Clover.-.S01E32.MKV./.H.264./.AAC./.HDTV./.Legendado./.Japonês./.1080p with 8 seeders and 0 leechers and size 547.08 MB from BJ-Share
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] GET URL: https://bj-share.me/torrents.php?action=download&id=153167&authkey=a04a6d622a11a69cacc0bc6180c14c13&torrent_pass=n8y6e8lkljrp78gixy4651vutqueo2pg [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Calling qbittorrent Client
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] GET URL: http://localhost:9496/version/api [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] POST URL: http://localhost:9496/login [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] With post data: username=**********&password=**********
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] qbittorrent: Requested a POST connection to http://localhost:9496/command/upload with params: None Data: None
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] POST URL: http://localhost:9496/command/upload [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
 Content-Disposition: form-data; name="torrents"; filename*=utf-...
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] qbittorrent: Response to POST request is 
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] GET URL: http://localhost:9496/version/api [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] qbittorrent: Requested a POST connection to http://localhost:9496/version/api with params: None Data: {u'hash': '2b44e208ac311fae598013251bb7bfbd9e16ba9d'}
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] POST URL: http://localhost:9496/version/api [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] With post data: hash=2b44e208ac311fae598013251bb7bfbd9e16ba9d
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] qbittorrent: Response to POST request is 17
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] GET URL: http://localhost:9496/version/api [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] GET URL: http://localhost:9496/version/api [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] qbittorrent: Requested a POST connection to http://localhost:9496/command/setCategory with params: None Data: {u'category': u'medusa', u'hashes': '2b44e208ac311fae598013251bb7bfbd9e16ba9d'}
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] POST URL: http://localhost:9496/command/setCategory [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] With post data: category=medusa&hashes=2b44e208ac311fae598013251bb7bfbd9e16ba9d
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] qbittorrent: Response to POST request is 
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] qbittorrent: Requested a POST connection to http://localhost:9496/command/increasePrio with params: None Data: {u'hashes': '2b44e208ac311fae598013251bb7bfbd9e16ba9d'}
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] POST URL: http://localhost:9496/command/increasePrio [Status: 200]
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] User-Agent: Medusa/0.2.2 (Windows; 10; cdb05a61-5ab4-11e8-92f1-7cdd9083bde4)
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] With post data: hashes=2b44e208ac311fae598013251bb7bfbd9e16ba9d
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] qbittorrent: Response to POST request is 
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Checking if we should stop searching for a better quality for for episode Black.Clover.-.S01E32.MKV./.H.264./.AAC./.HDTV./.Legendado./.Japonês./.1080p
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Matched release G:\Meu Drive\Media\Animes\Black Clover\Season 1\Black.Clover.S01E32.032.1080p.HDTV-Multiple Subtitle to a series in your database: Black Clover
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Parsed G:\Meu Drive\Media\Animes\Black Clover\Season 1\Black.Clover.S01E32.032.1080p.HDTV-Multiple Subtitle into title: Black Clover, season: 1, episode: [32], episode_title: 032, screen_size: 1080p, format: HDTV, release_group: Multiple Subtitle, type: episode, parsing_time: 0.169000148773, total_time: 0.169000148773, absolute_episode: [], quality: 1080p HDTV
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Found codec for Black Clover Three-Leaf Sprouts
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] 331753: Episode has no release group, replacing it with Multiple Subtitle
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] 331753: Formatting pattern: %SN - %Sx32 - 032 - %EN - %QN -> Black Clover - 1x32 - 032 - Three-Leaf Sprouts - 1080p HDTV
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Sending a Telegram message for Black Clover - 1x32 - 032 - Three-Leaf Sprouts - 1080p HDTV with 8 seeders and 0 leechers from BJ-Share
2018-05-18 13:04:07 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Telegram in use with API KEY: **********
2018-05-18 13:04:08 INFO     SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Telegram message sent successfully.
2018-05-18 13:04:08 DEBUG    SNATCHQUEUE-MANUALSNATCH-331753 :: [71edd70] Transaction with 1 queries executed```



Discussion:
Tested with uTorrent and it worked fine, seens that this problem is only with qBittorrent

Resolving patch:
diff --git a/medusa/clients/torrent/generic.py b/medusa/clients/torrent/generic.py
--- a/medusa/clients/torrent/generic.py
+++ b/medusa/clients/torrent/generic.py
@@ -61,14 +61,16 @@ def _request(self, method='get', params=None, data=None, files=None, cookies=Non
 
         text_params = str(params)
         text_data = str(data)
+        text_files = str(files)
         log.debug(
             '{name}: Requested a {method} connection to {url} with'
-            ' params: {params} Data: {data}', {
+            ' params: {params} Data: {data} Files: {files}', {
                 'name': self.name,
                 'method': method.upper(),
                 'url': self.url,
                 'params': text_params[0:99] + '...' if len(text_params) > 102 else text_params,
-                'data': text_data[0:99] + '...' if len(text_data) > 102 else text_data
+                'data': text_data[0:99] + '...' if len(text_data) > 102 else text_data,
+                'files': text_files[0:99] + '...' if len(text_files) > 102 else text_files,
             }
         )
 
diff --git a/medusa/clients/torrent/qbittorrent_client.py b/medusa/clients/torrent/qbittorrent_client.py
--- a/medusa/clients/torrent/qbittorrent_client.py
+++ b/medusa/clients/torrent/qbittorrent_client.py
@@ -80,10 +80,7 @@ def _add_torrent_file(self, result):
 
         self.url = '{host}command/upload'.format(host=self.host)
         files = {
-            'torrents': (
-                '{result}.torrent'.format(result=result.name),
-                result.content,
-            ),
+            'torrents': result.content
         }
         return self._request(method='post', files=files, cookies=self.session.cookies)
 


Test patch: