Skip to content

Commit e077e5d

Browse files
authored
fix(eos_downloader): Add User Agent in HTTP requests (#82)
1 parent e370e17 commit e077e5d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

eos_downloader/download.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
console = rich.get_console()
2727
done_event = Event()
2828

29+
REQUEST_HEADERS = {
30+
"Content-Type": "application/json",
31+
"User-Agent": "Chrome/123.0.0.0",
32+
}
33+
2934

3035
def handle_sigint(signum: Any, frame: Any) -> None:
3136
"""Progress bar handler"""
@@ -64,7 +69,7 @@ def _copy_url(
6469
self, task_id: TaskID, url: str, path: str, block_size: int = 1024
6570
) -> bool:
6671
"""Copy data from a url to a local file."""
67-
response = requests.get(url, stream=True, timeout=5)
72+
response = requests.get(url, stream=True, timeout=5, headers=REQUEST_HEADERS)
6873
# This will break if the response doesn't contain content length
6974
self.progress.update(task_id, total=int(response.headers["Content-Length"]))
7075
with open(path, "wb") as dest_file:

eos_downloader/object_downloader.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
MSG_TOKEN_EXPIRED,
4141
)
4242
from eos_downloader.data import DATA_MAPPING
43-
from eos_downloader.download import DownloadProgressBar
43+
from eos_downloader.download import DownloadProgressBar, REQUEST_HEADERS
4444

4545
# logger = logging.getLogger(__name__)
4646

@@ -263,7 +263,10 @@ def get_folder_tree(self) -> ET.ElementTree:
263263
self.authenticate()
264264
jsonpost = {"sessionCode": self.session_id}
265265
result = requests.post(
266-
ARISTA_SOFTWARE_FOLDER_TREE, data=json.dumps(jsonpost), timeout=self.timeout
266+
ARISTA_SOFTWARE_FOLDER_TREE,
267+
data=json.dumps(jsonpost),
268+
timeout=self.timeout,
269+
headers=REQUEST_HEADERS,
267270
)
268271
try:
269272
folder_tree = result.json()["data"]["xml"]
@@ -332,7 +335,10 @@ def _get_url(self, remote_file_path: str) -> str:
332335
self.authenticate()
333336
jsonpost = {"sessionCode": self.session_id, "filePath": remote_file_path}
334337
result = requests.post(
335-
ARISTA_DOWNLOAD_URL, data=json.dumps(jsonpost), timeout=self.timeout
338+
ARISTA_DOWNLOAD_URL,
339+
data=json.dumps(jsonpost),
340+
timeout=self.timeout,
341+
headers=REQUEST_HEADERS,
336342
)
337343
if "data" in result.json() and "url" in result.json()["data"]:
338344
# logger.debug('URL to download file is: {}', result.json())
@@ -421,7 +427,10 @@ def authenticate(self) -> bool:
421427
jsonpost = {"accessToken": credentials}
422428

423429
result = requests.post(
424-
session_code_url, data=json.dumps(jsonpost), timeout=self.timeout
430+
session_code_url,
431+
data=json.dumps(jsonpost),
432+
timeout=self.timeout,
433+
headers=REQUEST_HEADERS,
425434
)
426435

427436
if result.json()["status"]["message"] in [

0 commit comments

Comments
 (0)