Repository: pymedusa/Medusa

Issue:
DownloadStation Error
**Describe the bug**
Synology Download dont work.

When sending is torrent to Syno Download the error program, and does not send anything ...

When I installed I also had to change the class name **download_station_client.py** to 
 **downloadstation_client.py** to test.

Any help? I really wanted to change SickRage

**To Reproduce**
Steps to reproduce the behavior:
1. Send Torrent to DownloadStation

**Expected behavior**
Torrent Added to DownloadStation


**Medusa (please complete the following information):**
 - OS: Linux-3.10.102-x86_64-with-glibc2.2.5 (XPEnology on Baremetal)
 - Branch: master
 - Commit: 0c0a73583452f988c518adeafa75ee1f17987bdf 
 - Python Version: 2.7.14 (default, May 28 2018, 14:47:18) [GCC 4.7.3 20130102 (prerelease)]
 -  SSL Version: OpenSSL 1.0.2n 7 Dec 2017

**Logs:**
<details>```

2018-11-02 10:26:09 WARNING  SNATCHQUEUE-MANUALSNATCH-349661 :: [0c0a735] DownloadStation: Unable to send Torrent
2018-11-02 10:26:09 WARNING  SNATCHQUEUE-MANUALSNATCH-349661 :: [0c0a735] Error: {u'success': False, u'error': {u'code': 403}}
2018-11-02 10:26:09 ERROR    SNATCHQUEUE-MANUALSNATCH-349661 :: [0c0a735] BraceMessage string formatting failed. Using representation instead.
Traceback (most recent call last):
  File "/volume4/@appstore/sickbeard-custom/var/SickBeard/medusa/logger/adapters/style.py", line 53, in __str__
    return self.msg.format(*args)
KeyError: u"u'version'"
Traceback (most recent call last):
  File "/volume4/@appstore/sickbeard-custom/var/SickBeard/medusa/logger/adapters/style.py", line 60, in __str__
    raise BraceException(self.msg)
BraceException: Add torrent URI with data: {u'version': u'1', u'api': u'SYNO.DownloadStation.Task', u'destination': u'/volume3/Downloads/Series', u'uri': u'magnet:?xt=urn:btih:bf4c68569d5dafbf4817a92fa16f4b6fb578120a&dn=The.Purge.S01E09.1080p.WEB.x264-TBS%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce&tr=udp://tracker.coppersurfer.tk:6969/announce&tr=udp://tracker.leechers-paradise.org:6969/announce&tr=udp://tracker.zer0day.to:1337/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=http://tracker.opentrackr.org:1337/announce&tr=udp://p4p.arenabg.com:1337/announce&tr=http://p4p.arenabg.com:1337/announce&tr=udp://explodie.org:6969/announce&tr=udp://9.rarbg.com:2710/announce&tr=http://explodie.org:6969/announce&tr=http://tracker.dler.org:6969/announce&tr=udp://public.popcorn-tracker.org:6969/announce&tr=udp://tracker.internetwarriors.net:1337/announce&tr=udp://ipv4.tracker.harry.lu:80/announce&tr=http://ipv4.tracker.harry.lu:80/announce&tr=udp://mgtracker.org:2710/announce&tr=http://mgtracker.org:6969/announce&tr=udp://tracker.mg64.net:6969/announce&tr=http://tracker.mg64.net:6881/announce&tr=http://torrentsmd.com:8080/announce', u'session': u'DownloadStation', u'method': u'create'}
2018-11-02 10:26:09 ERROR    SNATCHQUEUE-MANUALSNATCH-349661 :: [0c0a735] BraceMessage string formatting failed. Using representation instead.
Traceback (most recent call last):
  File "/volume4/@appstore/sickbeard-custom/var/SickBeard/medusa/logger/adapters/style.py", line 53, in __str__
    return self.msg.format(*args)
KeyError: u"u'version'"
Traceback (most recent call last):
  File "/volume4/@appstore/sickbeard-custom/var/SickBeard/medusa/logger/adapters/style.py", line 60, in __str__
    raise BraceException(self.msg)
BraceException: Add torrent URI with data: {u'version': u'1', u'api': u'SYNO.DownloadStation.Task', u'destination': u'/volume3/Downloads/Series', u'uri': u'magnet:?xt=urn:btih:bf4c68569d5dafbf4817a92fa16f4b6fb578120a&dn=The.Purge.S01E09.1080p.WEB.x264-TBS%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce&tr=udp://tracker.coppersurfer.tk:6969/announce&tr=udp://tracker.leechers-paradise.org:6969/announce&tr=udp://tracker.zer0day.to:1337/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=http://tracker.opentrackr.org:1337/announce&tr=udp://p4p.arenabg.com:1337/announce&tr=http://p4p.arenabg.com:1337/announce&tr=udp://explodie.org:6969/announce&tr=udp://9.rarbg.com:2710/announce&tr=http://explodie.org:6969/announce&tr=http://tracker.dler.org:6969/announce&tr=udp://public.popcorn-tracker.org:6969/announce&tr=udp://tracker.internetwarriors.net:1337/announce&tr=udp://ipv4.tracker.harry.lu:80/announce&tr=http://ipv4.tracker.harry.lu:80/announce&tr=udp://mgtracker.org:2710/announce&tr=http://mgtracker.org:6969/announce&tr=udp://tracker.mg64.net:6969/announce&tr=http://tracker.mg64.net:6881/announce&tr=http://torrentsmd.com:8080/announce', u'session': u'DownloadStation', u'method': u'create'}
```</details>



Discussion:
This is already fixed, see: https://github.com/pymedusa/Medusa/pull/5573
You can manually modify the files, switch to develop or wait for the next release.
Hello Switch to develop dont fix problem, change files also does not solve, try to wait to next release
Post the debug log error please.
Hello the log is

```
`2018-11-02 14:33:33 ERROR    SNATCHQUEUE-MANUALSNATCH-268592 :: [0c0a735] BraceMessage string formatting failed. Using representation instead.
Traceback (most recent call last):
  File "/volume4/@appstore/sickbeard-custom/var/SickBeard/medusa/logger/adapters/style.py", line 53, in __str__
    return self.msg.format(*args)
KeyError: u'"version"'
Traceback (most recent call last):
  File "/volume4/@appstore/sickbeard-custom/var/SickBeard/medusa/logger/adapters/style.py", line 60, in __str__
    raise BraceException(self.msg)
BraceException: ###Add torrent URI with data: {"version": "1", "api": "SYNO.DownloadStation.Task", "destination": "/volume3/Downloads/Series", "uri": "magnet:?xt=urn:btih:2fb39f9b0b55ce95b9b024d8866a02d458d02a68&dn=The.100.S05E13.REPACK.1080p.WEB.x264-METCON%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce&tr=udp://tracker.coppersurfer.tk:6969/announce&tr=udp://tracker.leechers-paradise.org:6969/announce&tr=udp://tracker.zer0day.to:1337/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=http://tracker.opentrackr.org:1337/announce&tr=udp://p4p.arenabg.com:1337/announce&tr=http://p4p.arenabg.com:1337/announce&tr=udp://explodie.org:6969/announce&tr=udp://9.rarbg.com:2710/announce&tr=http://explodie.org:6969/announce&tr=http://tracker.dler.org:6969/announce&tr=udp://public.popcorn-tracker.org:6969/announce&tr=udp://tracker.internetwarriors.net:1337/announce&tr=udp://ipv4.tracker.harry.lu:80/announce&tr=http://ipv4.tracker.harry.lu:80/announce&tr=udp://mgtracker.org:2710/announce&tr=http://mgtracker.org:6969/announce&tr=udp://tracker.mg64.net:6969/announce&tr=http://tracker.mg64.net:6881/announce&tr=http://torrentsmd.com:8080/announce", "session": "DownloadStation", "method": "create"}
````

I changed the log to make sure the file was being changed correctly
```

 def _add_torrent_uri(self, result):

        torrent_path = app.TORRENT_PATH

        data = {
            'api': 'SYNO.DownloadStation.Task',
            'version': '1',
            'method': 'create',
            'session': 'DownloadStation',
            'uri': result.url,
        }

        if not self._check_destination():
            return False

        if torrent_path:
            data['destination'] = torrent_path

        log.debug('###Add torrent URI with data: {0}'.format(json.dumps(data)))
        self._request(method='post', data=data)
        return self._check_response()
```

Please change ```log.debug('###Add torrent URI with data: {0}'.format(json.dumps(data)))``` to ```log.debug('###Add torrent URI with data: {0}', json.dumps(data))``` and see if that works.
Thus no error ... but also does not write anything in the log ... However still without adding to DownloadStation

```
2018-11-02 14:52:13 WARNING  SNATCHQUEUE-MANUALSNATCH-268592 :: [0c0a735] DownloadStation: Unable to send Torrent
2018-11-02 14:52:13 WARNING  SNATCHQUEUE-MANUALSNATCH-268592 :: [0c0a735] Error: {u'success': False, u'error': {u'code': 403}}
2018-11-02 14:52:13 INFO     SNATCHQUEUE-MANUALSNATCH-268592 :: [0c0a735] Destination is now /volume3/Downloads/Series
2018-11-02 14:52:12 INFO     SNATCHQUEUE-MANUALSNATCH-268592 :: [0c0a735] Downloading The.100.S05E13.REPACK.1080p.WEB.x264-METCON[rartv] with 23 seeders and 2 leechers and size 1.88 GB from Rarbg
2018-11-02 14:52:12 INFO     SNATCHQUEUE-MANUALSNATCH-268592 :: [0c0a735] Beginning to manual snatch release: The.100.S05E13.REPACK.1080p.WEB.x264-METCON[rartv]
```

gives the 402 forbidden error

Thanks, you need to enable debug log to see it. Not sure about about the other issue, I don't have a Synology NAS to test it, check your settings/permissions?
Reinstall everything and change file with the 
`log.debug('###Add torrent URI with data: {0}', json.dumps(data)) `

E found another problem the torrent search provider setting dont sabe after restart 

and now all works

Resolving patch:
diff --git a/medusa/clients/torrent/downloadstation_client.py b/medusa/clients/torrent/downloadstation_client.py
--- a/medusa/clients/torrent/downloadstation_client.py
+++ b/medusa/clients/torrent/downloadstation_client.py
@@ -121,7 +121,7 @@ def _add_torrent_uri(self, result):
 
         if torrent_path:
             data['destination'] = torrent_path
-        log.debug('Add torrent URI with data: {0}'.format(json.dumps(data)))
+        log.debug('Add torrent URI with data: {0}', json.dumps(data))
         self._request(method='post', data=data)
         return self._check_response()
 
@@ -144,7 +144,7 @@ def _add_torrent_file(self, result):
 
         files = {'file': ('{name}.torrent'.format(name=result.name), result.content)}
 
-        log.debug('Add torrent files with data: {0}'.format(json.dumps(data)))
+        log.debug('Add torrent files with data: {0}', json.dumps(data))
         self._request(method='post', data=data, files=files)
         return self._check_response()
 


Test patch: