MCPcopy
hub / github.com/encode/httpx / BasicAuth

Class BasicAuth

httpx/_auth.py:126–142  ·  view source on GitHub ↗

Allows the 'auth' argument to be passed as a (username, password) pair, and uses HTTP Basic authentication.

Source from the content-addressed store, hash-verified

124
125
126class BasicAuth(Auth):
127 """
128 Allows the 'auth' argument to be passed as a (username, password) pair,
129 and uses HTTP Basic authentication.
130 """
131
132 def __init__(self, username: str | bytes, password: str | bytes) -> None:
133 self._auth_header = self._build_auth_header(username, password)
134
135 def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
136 request.headers["Authorization"] = self._auth_header
137 yield request
138
139 def _build_auth_header(self, username: str | bytes, password: str | bytes) -> str:
140 userpass = b":".join((to_bytes(username), to_bytes(password)))
141 token = b64encode(userpass).decode()
142 return f"Basic {token}"
143
144
145class NetRCAuth(Auth):

Callers 2

_build_authMethod · 0.85
_build_request_authMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected