Run API Call Using Python #pythontutorial
Code for Practice
import requests
import pandas as pd
Replace 'YOUR_USERNAME' and 'YOUR_PASSWORD' with your actual credentials
username = 'XXXXXXXXXXXXX'
password = 'Pblu496F9Z'
url = 'https://api.meteomatics.com/2024-02-2...
Sending a GET request with basic authentication
response = requests.get(url, auth=(username, password))
if response.status_code == 200:
try:
data = response.json()
print(data) # Print the JSON data to inspect
Check if the response is empty or not in the expected JSON format
if not data:
print("Empty response or not in JSON format.")
else:
Assuming data is a list of dictionaries, you may need to adapt this based on the API response format
df = pd.DataFrame(data)
Specify the path where you want to save the Excel file
excel_file_path = "output_data.xlsx"
Save the DataFrame to Excel
df.to_excel(excel_file_path, index=False)
print(f"Data saved to {excel_file_path}")
except requests.exceptions.JSONDecodeError as e:
print(f"Error decoding JSON: {e}")
else:
print(f"Error: {response.status_code}")
print(response.text) # Print the response content for inspection
Auf dieser Seite können Sie das Online-Video Run API Call Using Python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer InfoTech Essence 17 März 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 144 Mal angesehen und es wurde von 10 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!