Select to view content in your preferred language

How to download data from OPEN ET using python for ArcGIS

103
2
Jump to solution
Wednesday
Labels (3)
CephasHurr
New Contributor

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

0 Kudos
1 Solution

Accepted Solutions
JeffSilberberg
Frequent Contributor

ChatGPT says ---

It looks like you're very close, but your Python script has two issues:

  1. Syntax error in the payload dictionary — you're missing a comma before "reference_et".

  2. Indentation error under if response.status_code == 200: — your block is not indented.

View solution in original post

0 Kudos
2 Replies
JeffSilberberg
Frequent Contributor

ChatGPT says ---

It looks like you're very close, but your Python script has two issues:

  1. Syntax error in the payload dictionary — you're missing a comma before "reference_et".

  2. Indentation error under if response.status_code == 200: — your block is not indented.

0 Kudos
CephasHurr
New Contributor

Thanks Jeff! It worked!

0 Kudos