Skip to content

Commit

Permalink
Requests fix for Archer C2300 v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrErohin committed Mar 23, 2024
1 parent dccddd8 commit 303d107
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ or you have TP-link C1200 V2 or similar router you need to get web encrypted pas
- Archer AX6000 V1
- Archer AX11000 V1
- Archer C1200 v2.0 (You need to use [web encrypted password](#encrypted_pass))
- Archer C2300 v1.0 (You need to use [web encrypted password](#encrypted_pass))
- Archer C6 v2.0
- Archer C6 v3.0
- Archer C6U v1.0
- Archer C7 v5.0
- Archer C2300 v1.0
- Archer MR200 v5
- Archer MR200 v5.3
- Archer MR600 v1
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="tplinkrouterc6u",
version="3.4.1",
version="3.4.2",
author="Alex Erohin",
author_email="[email protected]",
description="TP-Link Router API",
Expand Down
15 changes: 10 additions & 5 deletions tplinkrouterc6u/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class TplinkRequest:
_sysauth = None
_verify_ssl = False
_logger = None
_headers = {'Content-Type': 'application/x-www-form-urlencoded'}
_headers_request = {}
_headers_login = {}
_data_block = 'data'

def request(self, path: str, data: str, ignore_response: bool = False, ignore_errors: bool = False) -> dict | None:
Expand All @@ -78,7 +79,7 @@ def request(self, path: str, data: str, ignore_response: bool = False, ignore_er
response = requests.post(
url,
data=self._prepare_data(data),
headers=self._headers,
headers=self._headers_request,
cookies={'sysauth': self._sysauth},
timeout=self.timeout,
verify=self._verify_ssl,
Expand Down Expand Up @@ -240,7 +241,7 @@ def _try_login(self) -> requests.Response:
return requests.post(
url,
data=body,
headers=self._headers,
headers=self._headers_login,
timeout=self.timeout,
verify=self._verify_ssl,
)
Expand Down Expand Up @@ -272,6 +273,9 @@ def __init__(self, host: str, password: str, username: str = 'admin', logger: Lo
self._url_wireless_stats = 'admin/wireless?form=statistics&operation=read'
self._url_ipv4_reservations = 'admin/dhcps?form=reservation&operation=load'
self._url_ipv4_dhcp_leases = 'admin/dhcps?form=client&operation=load'
referer = '{}/webpages/index.html'.format(self.host)
self._headers_request = {'Referer': referer}
self._headers_login = {'Referer': referer, 'Content-Type': 'application/x-www-form-urlencoded'}

@abstractmethod
def authorize(self) -> bool:
Expand Down Expand Up @@ -430,7 +434,8 @@ def __init__(self, host: str, password: str, username: str = 'admin', logger: Lo
verify_ssl: bool = True, timeout: int = 10) -> None:
super().__init__(host, password, username, logger, verify_ssl, timeout)

self._headers = {'Content-Type': 'application/json'}
self._headers_request = {'Content-Type': 'application/json'}
self._headers_login = {'Content-Type': 'application/json'}
self._data_block = 'result'
self.devices = []

Expand Down Expand Up @@ -587,7 +592,7 @@ def authorize(self) -> None:
response = requests.post(
url,
params={'operation': 'login', 'username': self.username, 'password': self.password},
headers={'Content-Type': 'application/x-www-form-urlencoded'},
headers=self._headers_login,
timeout=self.timeout,
verify=self._verify_ssl,
)
Expand Down

0 comments on commit 303d107

Please sign in to comment.