|
10 | 10 | from socket import getdefaulttimeout as get_default_timeout |
11 | 11 | from typing import Container, Dict, List, Optional, Text, Tuple, Union |
12 | 12 |
|
13 | | -from requests import Response, codes, request |
| 13 | +from requests import Response, codes, request, auth |
14 | 14 | from six import PY2, binary_type, iteritems, moves as compat, text_type, \ |
15 | 15 | with_metaclass |
16 | 16 |
|
@@ -223,11 +223,12 @@ class HttpAdapter(BaseAdapter): |
223 | 223 | in the ``headers`` kwarg. |
224 | 224 | """ |
225 | 225 |
|
226 | | - def __init__(self, uri, timeout=None): |
| 226 | + def __init__(self, uri, timeout=None, authentication=None): |
227 | 227 | # type: (Union[Text, SplitResult], Optional[int]) -> None |
228 | 228 | super(HttpAdapter, self).__init__() |
229 | 229 |
|
230 | 230 | self.timeout = timeout |
| 231 | + self.authentication = authentication |
231 | 232 |
|
232 | 233 | if isinstance(uri, text_type): |
233 | 234 | uri = compat.urllib_parse.urlsplit(uri) # type: SplitResult |
@@ -313,6 +314,8 @@ def _send_http_request(self, url, payload, method='post', **kwargs): |
313 | 314 |
|
314 | 315 | default_timeout = self.timeout if self.timeout else get_default_timeout() |
315 | 316 | kwargs.setdefault('timeout', default_timeout) |
| 317 | + if self.authentication: |
| 318 | + kwargs.setdefault('auth', auth.HTTPBasicAuth(*self.authentication)) |
316 | 319 |
|
317 | 320 | self._log( |
318 | 321 | level = DEBUG, |
|
0 commit comments