summaryrefslogtreecommitdiffstats
path: root/eos_downloader
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 20:03:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 20:03:28 +0000
commitc1bdf05e08f7e8d8ba3d3f392784b291077ee520 (patch)
tree16b542a49cee5dbed163f874b14f15de82c200e2 /eos_downloader
parentReleasing debian version 0.10.0-1. (diff)
downloadeos-downloader-c1bdf05e08f7e8d8ba3d3f392784b291077ee520.tar.xz
eos-downloader-c1bdf05e08f7e8d8ba3d3f392784b291077ee520.zip
Merging upstream version 0.10.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'eos_downloader')
-rw-r--r--eos_downloader/download.py7
-rw-r--r--eos_downloader/object_downloader.py17
2 files changed, 19 insertions, 5 deletions
diff --git a/eos_downloader/download.py b/eos_downloader/download.py
index 2c9576e..df3c381 100644
--- a/eos_downloader/download.py
+++ b/eos_downloader/download.py
@@ -26,6 +26,11 @@ from rich.progress import (
console = rich.get_console()
done_event = Event()
+REQUEST_HEADERS = {
+ "Content-Type": "application/json",
+ "User-Agent": "Chrome/123.0.0.0",
+}
+
def handle_sigint(signum: Any, frame: Any) -> None:
"""Progress bar handler"""
@@ -64,7 +69,7 @@ class DownloadProgressBar:
self, task_id: TaskID, url: str, path: str, block_size: int = 1024
) -> bool:
"""Copy data from a url to a local file."""
- response = requests.get(url, stream=True, timeout=5)
+ response = requests.get(url, stream=True, timeout=5, headers=REQUEST_HEADERS)
# This will break if the response doesn't contain content length
self.progress.update(task_id, total=int(response.headers["Content-Length"]))
with open(path, "wb") as dest_file:
diff --git a/eos_downloader/object_downloader.py b/eos_downloader/object_downloader.py
index 30cf9df..c107fee 100644
--- a/eos_downloader/object_downloader.py
+++ b/eos_downloader/object_downloader.py
@@ -40,7 +40,7 @@ from eos_downloader import (
MSG_TOKEN_EXPIRED,
)
from eos_downloader.data import DATA_MAPPING
-from eos_downloader.download import DownloadProgressBar
+from eos_downloader.download import DownloadProgressBar, REQUEST_HEADERS
# logger = logging.getLogger(__name__)
@@ -263,7 +263,10 @@ class ObjectDownloader:
self.authenticate()
jsonpost = {"sessionCode": self.session_id}
result = requests.post(
- ARISTA_SOFTWARE_FOLDER_TREE, data=json.dumps(jsonpost), timeout=self.timeout
+ ARISTA_SOFTWARE_FOLDER_TREE,
+ data=json.dumps(jsonpost),
+ timeout=self.timeout,
+ headers=REQUEST_HEADERS,
)
try:
folder_tree = result.json()["data"]["xml"]
@@ -332,7 +335,10 @@ class ObjectDownloader:
self.authenticate()
jsonpost = {"sessionCode": self.session_id, "filePath": remote_file_path}
result = requests.post(
- ARISTA_DOWNLOAD_URL, data=json.dumps(jsonpost), timeout=self.timeout
+ ARISTA_DOWNLOAD_URL,
+ data=json.dumps(jsonpost),
+ timeout=self.timeout,
+ headers=REQUEST_HEADERS,
)
if "data" in result.json() and "url" in result.json()["data"]:
# logger.debug('URL to download file is: {}', result.json())
@@ -421,7 +427,10 @@ class ObjectDownloader:
jsonpost = {"accessToken": credentials}
result = requests.post(
- session_code_url, data=json.dumps(jsonpost), timeout=self.timeout
+ session_code_url,
+ data=json.dumps(jsonpost),
+ timeout=self.timeout,
+ headers=REQUEST_HEADERS,
)
if result.json()["status"]["message"] in [