Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ HttpAdapter
api = Iota('https://service.iotasupport.com:14265')
api = Iota(HttpAdapter('https://service.iotasupport.com:14265'))

# Use HTTP with basic authentication and custom timeout:
api = Iota(HttpAdapter(
url='http://localhost:14265',
authentication=('username', 'longandsecureIRIpassword'),
timeout=60.))


``HttpAdapter`` uses the HTTP protocol to send requests to the node.

To configure an ``Iota`` instance to use ``HttpAdapter``, specify an
Expand Down
8 changes: 6 additions & 2 deletions iota/adapter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from socket import getdefaulttimeout as get_default_timeout
from typing import Container, Dict, List, Optional, Text, Tuple, Union

from requests import Response, codes, request
from requests import Response, codes, request, auth
from six import PY2, binary_type, iteritems, moves as compat, text_type, \
with_metaclass

Expand Down Expand Up @@ -223,11 +223,12 @@ class HttpAdapter(BaseAdapter):
in the ``headers`` kwarg.
"""

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

self.timeout = timeout
self.authentication = authentication

if isinstance(uri, text_type):
uri = compat.urllib_parse.urlsplit(uri) # type: SplitResult
Expand Down Expand Up @@ -314,6 +315,9 @@ def _send_http_request(self, url, payload, method='post', **kwargs):
default_timeout = self.timeout if self.timeout else get_default_timeout()
kwargs.setdefault('timeout', default_timeout)

if self.authentication:
kwargs.setdefault('auth', auth.HTTPBasicAuth(*self.authentication))

self._log(
level = DEBUG,

Expand Down