Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

from __future__ import unicode_literals

import base64
import os
import socket
import time
import threading
import time
from contextlib import closing
from wsgiref.simple_server import make_server
import base64
import sys

from . import core
try:
Expand Down Expand Up @@ -146,13 +145,9 @@ def handle():
'''Handler that implements HTTP Basic Auth.
'''
if username is not None and password is not None:
if sys.version_info >= (3,0):
auth_value = bytes('{0}:{1}'.format(username, password), 'utf8')
auth_token = str(base64.b64encode(auth_value), 'utf8')
else:
auth_value = '{0}:{1}'.format(username, password)
auth_token = base64.b64encode(auth_value)
auth_header = "Basic {0}".format(auth_token)
auth_value = '{0}:{1}'.format(username, password).encode('utf-8')
auth_token = base64.b64encode(auth_value)
auth_header = b'Basic ' + auth_token
headers.append(['Authorization', auth_header])
default_handler(url, method, timeout, headers, data)()

Expand Down