1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Plugin bitcoind_: fix base64 encoding for credentials

Python2.7 (as well as Python3.x) refused to execute the previously used
encoding (`foo.encode('base64')`).  It is unknown, whether it worked
before with an older Python version.
This commit is contained in:
Lars Kruse 2019-07-22 13:43:10 +02:00
parent 7f77bdf74c
commit b6a41513d7

View file

@ -50,6 +50,7 @@ Copyright (C) 2012 Mike Koss
=cut"""
import base64
import json
import os
import re
@ -236,9 +237,9 @@ class Proxy(object):
}
request = urllib.request.Request(self.service.url, json.dumps(data))
if self.service.username:
# Strip the newline from the b64 encoding!
b64 = ('%s:%s' % (self.service.username, self.service.password)).encode('base64')[:-1]
request.add_header('Authorization', 'Basic %s' % b64)
auth_string = '%s:%s' % (self.service.username, self.service.password)
auth_b64 = base64.urlsafe_b64encode(auth_string.encode()).decode()
request.add_header('Authorization', 'Basic %s' % auth_b64)
try:
body = urllib.request.urlopen(request).read()