Skip to main content

Retry downloading a binary file from a URL with timeout and optional SSL check.

Project description

download_retry.py

A simple Python command-line tool to repeatedly attempt downloading a binary file from a URL until successful or until a timeout is reached.

Features

  • Downloads binary data from a given URL
  • Skips SSL certificate validation by default (--insecure true)
  • Retries every delta_t seconds until max_t seconds have elapsed
  • Saves the result to a specified output file
  • Returns exit code 0 on success, 1 on failure

Requirements

  • Python 3.6+
  • requests package

Install dependencies using:

pip install -r requirements.txt


Installation

Clone the repository.

git clone git@github.com:gilweis/download_retry.git
cd download_retry

Usage

python -m download_retry --url --delta_t --max_t --out <output_filename> [--insecure true|false]

Arguments

Argument Description Example
--url The URL to download from https://example.com/file.bin
--delta_t Time between retries in seconds 5
--max_t Maximum total wait time in seconds 60
--out Output filename file.bin
--insecure Skip SSL verification (true by default) true or false

Examples

Default (insecure=True):

Skips SSL certificate verification:

python -m download_retry
--url "https://my.server.local/firmware.bin"
--delta_t 3
--max_t 60
--out firmware.bin

Enforce SSL certificate verification (insecure=False):

python -m download_retry
--url "https://secure.example.com/file.bin"
--delta_t 3
--max_t 60
--out secure.bin
--insecure false


Exit Codes

  • 0: File downloaded successfully
  • 1: Failed to download within time limit

Testing

To run tests:

  1. Install test requirements:

pip install pytest

  1. Run tests:

pytest tests/


Build and Install

To build source and wheel distributions:

python -m build

If you don't have the build tool installed:

pip install build

To install the package locally:

pip install .

To upload to PyPI (optional):

pip install twine twine upload dist/*


Warning

By default, SSL certificate validation is disabled using --insecure true. This may expose you to man-in-the-middle attacks. Use --insecure false to enforce SSL verification when downloading from public or sensitive endpoints.


License

MIT License

Version

0.1.2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

download_retry-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

download_retry-0.1.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file download_retry-0.1.2.tar.gz.

File metadata

  • Download URL: download_retry-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for download_retry-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c39b4a7117848c6b1742dceae7deb7c06d4ee860d5db68e8d8ce6ab07628f905
MD5 3cbc4c186e340569ccfff2e319241dfd
BLAKE2b-256 829b304c9109ab92ac9fcb1b61c59e6f5733dffbd98eb9d842c6ce68ee06a497

See more details on using hashes here.

File details

Details for the file download_retry-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: download_retry-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for download_retry-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 60770ca4899635b72880eaa8f13c11164453198f4da0becd4ddad58dd05b5157
MD5 15eefd8fc3a760b5fc50c3fc49993489
BLAKE2b-256 100a92365226f6eea1afd082afb3b6d5637f2e756bdf924d454d911a58a3b32b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page