8000 Resort to determining python version to work around base64 byte encod… · melnikk/client_python@444a748 · GitHub
[go: up one dir, main page]

Skip to content

Commit 444a748

Browse files
committed
Resort to determining python version to work around base64 byte encoding issue.
1 parent 8f7511a commit 444a748

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

prometheus_client/exposition.py

Lines changed: 7 additions & 2 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from contextlib import closing
1010
from wsgiref.simple_server import make_server
1111
import base64
12+
import sys
1213

1314
from . import core
1415
try:
@@ -145,8 +146,12 @@ def handle():
145146
'''Handler that implements HTTP Basic Auth.
146147
'''
147148
if username is not None and password is not None:
148-
auth_value = bytes('{0}:{1}'.format(username, password), 'utf8')
149-
auth_token = str(base64.b64encode(auth_value), 'utf8')
149+
if sys.version_info >= (3,0):
150+
auth_value = bytes('{0}:{1}'.format(username, password), 'utf8')
151+
auth_token = str(base64.b64encode(auth_value), 'utf8')
152+
else:
153+
auth_value = '{0}:{1}'.format(username, password)
154+
auth_token = base64.b64encode(auth_value)
150155
auth_header = "Basic {0}".format(auth_token)
151156
headers.append(['Authorization', auth_header])
152157
default_handler(url, method, timeout, headers, data)()

0 commit comments

Comments
 (0)
0