From 4c3b60be68fa4b1732f7553bdf959cbe94cdc8fc Mon Sep 17 00:00:00 2001 From: Noam Date: Sun, 17 Sep 2017 01:40:04 +0300 Subject: [PATCH 1/3] UnicodeDecodeError printing torrent name containing unicode --- headphones/deluge.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/headphones/deluge.py b/headphones/deluge.py index e17a6995..99bd1382 100644 --- a/headphones/deluge.py +++ b/headphones/deluge.py @@ -170,7 +170,10 @@ def addTorrent(link, data=None, name=None): # remove '.torrent' suffix if name[-len('.torrent'):] == '.torrent': name = name[:-len('.torrent')] - logger.debug('Deluge: Sending Deluge torrent with name %s and content [%s...]' % (name, str(torrentfile)[:40])) + try: + logger.debug('Deluge: Sending Deluge torrent with name %s and content [%s...]' % (name, str(torrentfile)[:40])) + except UnicodeDecodeError: + logger.debug('Deluge: Sending Deluge torrent with name %s and content [%s...]' % (name.decode('utf-8'), str(torrentfile)[:40])) result = {'type': 'torrent', 'name': name, 'content': torrentfile} From b7af246340fa5d5fea30d40d472705ae7b5ae9c2 Mon Sep 17 00:00:00 2001 From: Noam Date: Sun, 17 Sep 2017 02:10:30 +0300 Subject: [PATCH 2/3] Try encoding torrent name utf-8 in params --- headphones/deluge.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/headphones/deluge.py b/headphones/deluge.py index 99bd1382..07699b0b 100644 --- a/headphones/deluge.py +++ b/headphones/deluge.py @@ -471,7 +471,8 @@ def _add_torrent_file(result): try: # content is torrent file contents that needs to be encoded to base64 post_data = json.dumps({"method": "core.add_torrent_file", - "params": [result['name'] + '.torrent', b64encode(result['content'].encode('utf8')), {}], + "params": [result['name'].encode('utf8') + '.torrent', + b64encode(result['content'].encode('utf8')), {}], "id": 2}) response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth, verify=deluge_verify_cert, headers=headers) @@ -484,7 +485,8 @@ def _add_torrent_file(result): # this time let's try leaving the encoding as is logger.debug('Deluge: There was a decoding issue, let\'s try again') post_data = json.dumps({"method": "core.add_torrent_file", - "params": [result['name'] + '.torrent', b64encode(result['content']), {}], + "params": [result['name'] + '.torrent', + b64encode(result['content']), {}], "id": 22}) response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth, verify=deluge_verify_cert, headers=headers) From 68c551c8285942348341f69c640eafd029a63a82 Mon Sep 17 00:00:00 2001 From: Noam Date: Sun, 17 Sep 2017 02:40:09 +0300 Subject: [PATCH 3/3] Try DEcoding torrent name utf-8 in params --- headphones/deluge.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/headphones/deluge.py b/headphones/deluge.py index 07699b0b..5eb27849 100644 --- a/headphones/deluge.py +++ b/headphones/deluge.py @@ -471,7 +471,7 @@ def _add_torrent_file(result): try: # content is torrent file contents that needs to be encoded to base64 post_data = json.dumps({"method": "core.add_torrent_file", - "params": [result['name'].encode('utf8') + '.torrent', + "params": [result['name'] + '.torrent', b64encode(result['content'].encode('utf8')), {}], "id": 2}) response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth, @@ -485,7 +485,7 @@ def _add_torrent_file(result): # this time let's try leaving the encoding as is logger.debug('Deluge: There was a decoding issue, let\'s try again') post_data = json.dumps({"method": "core.add_torrent_file", - "params": [result['name'] + '.torrent', + "params": [result['name'].decode('utf8') + '.torrent', b64encode(result['content']), {}], "id": 22}) response = requests.post(delugeweb_url, data=post_data.encode('utf-8'), cookies=delugeweb_auth,