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

Commit 033d6ec

Browse files
authored
Merge pull request #142 from HerrMuellerluedenscheid/docs
HttpAdapter docs
2 parents b7e0ce0 + f1b5185 commit 033d6ec

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

docs/adapters.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ HttpAdapter
4444
api = Iota('https://service.iotasupport.com:14265')
4545
api = Iota(HttpAdapter('https://service.iotasupport.com:14265'))
4646
47+
# Use HTTPS with basic authentication and 60 seconds timeout:
48+
api = Iota(
49+
HttpAdapter(
50+
'https://service.iotasupport.com:14265',
51+
authentication=('myusername', 'mypassword'),
52+
timeout=60))
53+
4754
``HttpAdapter`` uses the HTTP protocol to send requests to the node.
4855

4956
To configure an ``Iota`` instance to use ``HttpAdapter``, specify an

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)