This Python script fetches data from the specified API URL and prints the JSON data to the console. It handles common errors, such as 502 Bad Gateway, 504 Gateway Timeout, and ConnectionError, by retrying the request with a delay.
- Python 3.6 or higher
requests
library
- Clone this repository or download the script.
- Install the required library using pip: pip install requests
- Open the
api_data_fetcher.py
script in a text editor. - Modify the
base_url
andaddress
variables to match the desired API endpoint and address. - Save the script and run it using the command: python api_data_fetcher.py
The script will fetch the data from the API and print it to the console. If an error is encountered, the script will retry the request up to the specified maximum number of retries.
You can adjust the max_retries
and retry_delay
parameters in the fetch_data
function to control the behavior of the retry mechanism.