Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit d669080

Browse files
author
Marius Kriegerowski
committed
HttpAdapter basic auth via requests module
1 parent d48083a commit d669080

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

iota/adapter/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from socket import getdefaulttimeout as get_default_timeout
1111
from typing import Container, Dict, List, Optional, Text, Tuple, Union
1212

13-
from requests import Response, codes, request
13+
from requests import Response, codes, request, auth
1414
from six import PY2, binary_type, iteritems, moves as compat, text_type, \
1515
with_metaclass
1616

@@ -223,11 +223,12 @@ class HttpAdapter(BaseAdapter):
223223
in the ``headers`` kwarg.
224224
"""
225225

226-
def __init__(self, uri, timeout=None):
226+
def __init__(self, uri, timeout=None, authentication=None):
227227
# type: (Union[Text, SplitResult], Optional[int]) -> None
228228
super(HttpAdapter, self).__init__()
229229

230230
self.timeout = timeout
231+
self.authentication = authentication
231232

232233
if isinstance(uri, text_type):
233234
uri = compat.urllib_parse.urlsplit(uri) # type: SplitResult
@@ -313,6 +314,8 @@ def _send_http_request(self, url, payload, method='post', **kwargs):
313314

314315
default_timeout = self.timeout if self.timeout else get_default_timeout()
315316
kwargs.setdefault('timeout', default_timeout)
317+
if self.authentication:
318+
kwargs.setdefault('auth', auth.HTTPBasicAuth(*self.authentication))
316319

317320
self._log(
318321
level = DEBUG,

0 commit comments

Comments
 (0)