MCPcopy Create free account
hub / github.com/aio-libs/aiohttp / encode_basic_auth

Function encode_basic_auth

aiohttp/helpers.py:119–128  ·  view source on GitHub ↗

Encode HTTP Basic Authentication credentials as an Authorization header value. Returns a string of the form ``"Basic "`` suitable for use as the value of the ``Authorization`` (or ``Proxy-Authorization``) header.

(login: str, password: str = "", encoding: str = "utf-8")

Source from the content-addressed store, hash-verified

117
118
119def encode_basic_auth(login: str, password: str = "", encoding: str = "utf-8") -> str:
120 """Encode HTTP Basic Authentication credentials as an Authorization header value.
121
122 Returns a string of the form ``"Basic <base64>"`` suitable for use as the
123 value of the ``Authorization`` (or ``Proxy-Authorization``) header.
124 """
125 if ":" in login:
126 raise ValueError('A ":" is not allowed in login (RFC 7617#section-2)')
127 creds = f"{login}:{password}".encode(encoding)
128 return "Basic " + base64.b64encode(creds).decode(encoding)
129
130
131class BasicAuth(namedtuple("BasicAuth", ["login", "password", "encoding"])):

Callers 1

encodeMethod · 0.85

Calls 2

encodeMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected