Hello,
I have the following code below, and it does not seem to work. When plugged into Gemini it seems to say that I need a reference_et file, but when I do add that parameter it spits out an error message. Is there a way that I can view what I need to pass as a parameter into payload to get the code to work?
import requests
import json
import os
from pathlib import Path
# Your OpenET API Key
API_KEY = "QbdUNjoQtrKCwGBqr3yHKFDC9z9G0HMdZWs2ZUzzfdgIrJTz9q0nuKGRz56m"
payload = {
"date_range": ["2020-01-01", "2020-12-31"],
"interval": "monthly",
"geometry": [-121.36322, 38.87626], # [longitude, latitude]
"model": "Ensemble",
"variable": "ET",
"units": "mm",
"file_format": "JSON" # Other formats like GeoJSON, CSV might be available depending on endpoint
# added required field here
"reference_et": True
}
headers = {
"accept": "application/json",
"Authorization": API_KEY,
"Content-Type": "application/json"
}
url = "https://openet-api.org/raster/timeseries/point"
# Make the POST request
response = requests.post(url, json=payload, headers=headers)
# Check if the request was successful
if response.status_code == 200:
data = response.json()
# Handle the data as a Python dictionary/list
print("Data successfully downloaded from OpenET API.")
else:
print(f"Error: {response.status_code} - {response.text}")
data = None
Solved! Go to Solution.
ChatGPT says ---
It looks like you're very close, but your Python script has two issues:
Syntax error in the payload dictionary — you're missing a comma before "reference_et".
Indentation error under if response.status_code == 200: — your block is not indented.
ChatGPT says ---
It looks like you're very close, but your Python script has two issues:
Syntax error in the payload dictionary — you're missing a comma before "reference_et".
Indentation error under if response.status_code == 200: — your block is not indented.
Thanks Jeff! It worked!