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

Plugin bitcoind_: switch to Python3

This commit is contained in:
Lars Kruse 2018-08-24 20:37:57 +02:00
parent fffb536e26
commit bc20826c4e

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""=cut
=head1 NAME
@ -48,12 +48,13 @@ Copyright (C) 2012 Mike Koss
=cut"""
import json
import os
import re
import sys
import time
import re
import urllib2
import json
import urllib.error
import urllib.request
DEBUG = False
@ -222,15 +223,15 @@ class Proxy(object):
'params': args,
'id': self.id,
}
request = urllib2.Request(self.service.url, json.dumps(data))
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)
try:
body = urllib2.urlopen(request).read()
except urllib2.URLError as e:
body = urllib.request.urlopen(request).read()
except urllib.error.URLError as e:
return (None, e)
if DEBUG:
@ -245,8 +246,8 @@ class Proxy(object):
def get_json_url(url):
request = urllib2.Request(url)
body = urllib2.urlopen(request).read()
request = urllib.request.Request(url)
body = urllib.request.urlopen(request).read()
data = json.loads(body)
return data