Bonjour,
Je rencontre un problème similaire, lorsque j'essaie de télécharger le fichier depuis l'interface avec le token que j'ai créé à partir de mon adresse IP, ça fonctionne alors que quand j'essaie de collecter les fichiers en Python, mes fichiers contiennent juste "Wrong IP Address". J'ai pensé que le problème pouvait venir de l'adresse IPv6 donc j'ai essayé de forcer l'utilisation d'IPv4 mais ça ne résoud pas le problème.
Je fournis pourtant bien l'IP de mon ordinateur et non celle de mon routeur.
@Picard Est-ce que tu pourrais m'en dire plus sur la manière dont tu as résolu le problème ?
Merci pour votre aide !
Axel
import argparse
import json
import os
import sys
from datetime import date, datetime, timedelta
import requests
from ofunctions.network import set_ip_version
if __name__ == "__main__":
# API URL
api_url = "https://www.infoclimat.fr/opendata/?method=get&format=csv&stations[]=ME099&stations[]=000BV"
# Token (replace with your actual token)
token = "xxxxxxxx"
# Start and end date
start_date = datetime.strptime("2023-01-01", "%Y-%m-%d")
end_date = datetime.strptime("2024-01-01", "%Y-%m-%d")
# Delta for one week
one_week_delta = timedelta(days=7)
# Loop through date windows
while start_date <= end_date:
# Calculate the end date for the current week
current_end_date = start_date + one_week_delta - timedelta(days=1)
# Format the dates as strings
start_date_str = start_date.strftime("%Y-%m-%d")
current_end_date_str = current_end_date.strftime("%Y-%m-%d")
local_filename = f"weather_data_{start_date_str}_{current_end_date_str}.csv"
# Construct the API request URL
request_url = f"{api_url}&start={start_date_str}&end={current_end_date_str}&token={token_2}"
set_ip_version(4)
# Make the API request
response = requests.get(request_url)
# Process the response (you can customize this part based on your needs)
if response.status_code == 200:
with open(local_filename, "wb") as file:
file.write(response.content)
print(f"File downloaded successfully as {local_filename}")
# Process the response content here, e.g., save it to a file or analyze the data
else:
print(f"Error collecting data. Status code: {response.status_code}")
print(response.text) # Print the response content for debugging
# Increment the start date for the next iteration
start_date += one_week_delta