diff --git a/freqtrade/tests/rpc/test_rpc_apiserver.py b/freqtrade/tests/rpc/test_rpc_apiserver.py index 620a7c34b..4c3aea89a 100644 --- a/freqtrade/tests/rpc/test_rpc_apiserver.py +++ b/freqtrade/tests/rpc/test_rpc_apiserver.py @@ -7,6 +7,7 @@ from unittest.mock import ANY, MagicMock, PropertyMock import pytest from flask import Flask +from requests.auth import _basic_auth_str from freqtrade.__init__ import __version__ from freqtrade.persistence import Trade @@ -37,18 +38,14 @@ def botclient(default_conf, mocker): def client_post(client, url, data={}): - headers = {"username": _TEST_USER, - "password": _TEST_PASS} return client.post(url, content_type="application/json", data=data, - headers=headers) + headers={'Authorization': _basic_auth_str(_TEST_USER, _TEST_PASS)}) def client_get(client, url): - headers = {"username": _TEST_USER, - "password": _TEST_PASS} - return client.get(url, headers=headers) + return client.get(url, headers={'Authorization': _basic_auth_str(_TEST_USER, _TEST_PASS)}) def assert_response(response, expected_code=200): @@ -95,8 +92,6 @@ def test_api_unauthorized(botclient): assert rc.json == {'error': 'Unauthorized'} - - def test_api_stop_workflow(botclient): ftbot, client = botclient assert ftbot.state == State.RUNNING diff --git a/scripts/rest_client.py b/scripts/rest_client.py index ca3da737e..2261fba0b 100755 --- a/scripts/rest_client.py +++ b/scripts/rest_client.py @@ -30,8 +30,7 @@ class FtRestClient(): self._serverurl = serverurl self._session = requests.Session() - self._username = username - self._password = password + self._session.auth = (username, password) def _call(self, method, apipath, params: dict = None, data=None, files=None): @@ -43,12 +42,6 @@ class FtRestClient(): "Content-Type": "application/json" } - if self._username: - hd.update({"username": self._username}) - - if self._password: - hd.update({"password": self._password}) - # Split url schema, netloc, path, par, query, fragment = urlparse(basepath) # URLEncode query string @@ -57,9 +50,7 @@ class FtRestClient(): url = urlunparse((schema, netloc, path, par, query, fragment)) try: - resp = self._session.request(method, url, headers=hd, data=json.dumps(data), - # auth=self.session.auth - ) + resp = self._session.request(method, url, headers=hd, data=json.dumps(data)) # return resp.text return resp.json() except ConnectionError: