Good Morning,
I have been pulling some item usage data from AGOL using the Python API item.usage().
Seems to be working fine for a few of the queries, and not for others.
My python:
from arcgis.gis import GIS,Item
gis = GIS("https://<organiztion>.maps.arcgis.com","<username>","<password>")
item = Item(gis,"<itemid>")
chartdata = item.usage("<daterange>",as_df=True)
print(chartdata)
The chart below shows which ones work for me.
If I run the 6M range, it returns:
Error generating usage report.
None
Error generating usage report
If I run the 1Y range, it returns:
Traceback (most recent call last):
File "<filepath>.py", line 12, in <module>
chartdata = item.usage("1Y",as_df=True)
File "<windowsuserfolder>\AppData\Local\ESRI\conda\envs\new-environment\lib\site-packages\arcgis\gis\__init__.py", line 6371, in usage
raise ValueError("Invalid date range.")
ValueError: Invalid date range.
It doesn't matter whether you return the Pandas DataFrame or the python dictionary for the result, same errors get generated.
Am I missing something somewhere?
It would be really nice to get the longer date ranges for my automated reporting I'm working on.
Thanks for any help on this!!
Cameron
Are you able to run the queries for 6 and 12 months in AGOL's web page interface? It could be an AGOL issue and what you are seeing is a symptom of that non-Python issue.
Yes both the 6 months and 1 year queries work in AGOL
It seems the maximum days in one request is restricted to 60 days.
I searched 1 year in AGOL, and the startTime and endTime in the requests sent by the browser to AGOL are:
startTime: 1512283405000
endTime: 1517467405000
startTime: 1517467405000
endTime: 1522655005000
startTime: 1522655005000
endTime: 1527839005000
startTime: 1527839005000
endTime: 1533023005000
startTime: 1533023005000
endTime: 1538207005000
startTime: 1538207005000
endTime: 1543387405000
startTime: 1543387405000
endTime: 1543819405000
Convert these timestamp (in milliseconds) to datetime, you'll find the regularity:
For example:
'2017-12-03 17:13:25'
Hi Cameron,
I was led here by your post in GitHub, and I also commented there.
item.usage() errors · Issue #321 · Esri/arcgis-python-api · GitHub
Hope it makes sense.
Simo
This specific issue has been address in the new release of 1.5.2.
arcgis-python-api/release-notes.ipynb at master · Esri/arcgis-python-api · GitHub