Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utf8 encode basic auth username/password #268

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -29,7 +29,7 @@
install_requires=[
"incremental",
"requests >= 2.1.0",
"six",
"six >= 1.12.0",
"Twisted[tls] >= 16.4.0 ; python_version < '3.7'",
"Twisted[tls] >= 18.7.0 ; python_version >= '3.7'",
"attrs",
Expand Down
8 changes: 6 additions & 2 deletions src/treq/auth.py
@@ -1,8 +1,11 @@
from __future__ import absolute_import, division, print_function

from twisted.web.http_headers import Headers
import base64

import six

from twisted.web.http_headers import Headers


class UnknownAuthConfig(Exception):
def __init__(self, config):
Expand All @@ -28,7 +31,8 @@ def request(self, method, uri, headers=None, bodyProducer=None):

def add_basic_auth(agent, username, password):
creds = base64.b64encode(
'{0}:{1}'.format(username, password).encode('ascii'))
b':'.join([six.ensure_binary(username), six.ensure_binary(password)])
)
return _RequestHeaderSettingAgent(
agent,
Headers({b'Authorization': [b'Basic ' + creds]}))
Expand Down