Skip to content

Commit 815711d

Browse files
committed
Fix nzbget settings test- Add authorization to test url
the username and password had to be base64 encoded. Issue #123
1 parent f7412b1 commit 815711d

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

modules/nzbget.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self):
2121
{'type': 'text', 'label': 'Port *', 'name': 'nzbget_port'},
2222
{'type': 'text', 'label': 'Basepath', 'name': 'nzbget_basepath'},
2323
{'type': 'text', 'label': 'User', 'name': 'nzbget_username'},
24-
{'type': 'text', 'label': 'Password', 'name': 'nzbget_password'},
24+
{'type': 'password', 'label': 'Password', 'name': 'nzbget_password'},
2525
{'type': 'bool', 'label': 'Use SSL', 'name': 'nzbget_ssl'}
2626
]})
2727

@@ -40,9 +40,14 @@ def version(self, nzbget_host, nzbget_basepath, nzbget_port, nzbget_username, nz
4040
if not(nzbget_basepath.endswith('/')):
4141
nzbget_basepath += "/"
4242

43-
url = 'http' + ssl + '://'+ nzbget_username + ':' + nzbget_password + '@' + nzbget_host + ':' + nzbget_port + nzbget_basepath + 'jsonrpc/'
43+
url = 'http' + ssl + '://'+ nzbget_host + ':' + nzbget_port + nzbget_basepath + 'jsonrpc/version'
4444
try:
45-
return loads(urlopen(url + 'version', timeout=10).read())
45+
request = Request(url)
46+
if(nzbget_username != ""):
47+
base64string = base64.encodestring(nzbget_username + ':' + nzbget_password).replace('\n', '')
48+
request.add_header("Authorization", "Basic %s" % base64string)
49+
self.logger.debug("Fetching information from: " + url)
50+
return loads(urlopen(request, timeout=10).read())
4651
except:
4752
self.logger.error("Unable to contact nzbget via " + url)
4853
return
@@ -64,7 +69,7 @@ def GetWarnings(self):
6469
def GetStatus(self):
6570
self.logger.debug("Fetching queue")
6671
return self.fetch('listgroups')
67-
72+
6873
def fetch(self, path):
6974
try:
7075
host = htpc.settings.get('nzbget_host', '')
@@ -78,11 +83,11 @@ def fetch(self, path):
7883
nzbget_basepath = "/"
7984
if not(nzbget_basepath.endswith('/')):
8085
nzbget_basepath += "/"
81-
86+
8287
url = 'http' + ssl + '://' + host + ':' + port + nzbget_basepath + 'jsonrpc/' + path
8388
request = Request(url)
8489
base64string = base64.encodestring(username + ':' + password).replace('\n', '')
85-
request.add_header("Authorization", "Basic %s" % base64string)
90+
request.add_header("Authorization", "Basic %s" % base64string)
8691
self.logger.debug("Fetching information from: " + url)
8792
return loads(urlopen(request, timeout=10).read())
8893
except:

0 commit comments

Comments
 (0)