Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.9k stars 1.11k forks source link

gis.admin.usage_reports.generate_report() failing unexpectedly with "Specified output format not supported" #2145

Open knoopum opened 3 weeks ago

knoopum commented 3 weeks ago

Describe the bug When attempting to run gis.admin.usage_reports.generate_report(), it fails unexpectedly with "Specified output format not supported" for certain report types. It appears to fail for "content", "activity", "credits", and "serviceUsages", while it appears to succeed for "user"; "itemUsages" fails differently with "invalid timeAggregate value"

The output format error appears to be an old bug (BUG-000142494), which indicates that it is not reproducible in the "current version" of the ArcGIS API for Python; however, that is not the case for me. This error occurs on multiple recent versions of the API, including 2.3.0.3 and 2.4.0.

To Reproduce Steps to reproduce the behavior:

import arcgis
from arcgis import GIS

# ArcGIS API for Python version:
print('ArcGIS API for Python version:', arcgis.__version__)

# Connect to default GIS.
gis = GIS("home")  

# Generate a weekly credit report
report_job = gis.admin.usage_reports.generate_report(
    report_type = 'credits',
    title = 'test',
    duration = 'weekly',
    future = False
)

error:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
/tmp/ipykernel_241/1627142702.py in <cell line: 0>()
      9 
     10 # Generate a weekly credit report
---> 11 report_job = gis.admin.usage_reports.generate_report(
     12     report_type = 'credits',
     13     title = 'test',

/opt/conda/lib/python3.11/site-packages/arcgis/gis/admin/_usage.py in generate_report(self, focus, report_type, title, duration, start_time, notify, future)
    154             params["startTime"] = start_time
    155         count = 0
--> 156         resp = self._con.post(url, params)
    157         if "itemId" in resp and future:
    158             from arcgis._impl._async.jobs import ItemStatusJob

/opt/conda/lib/python3.11/site-packages/arcgis/gis/_impl/_con/_connection.py in post(self, path, params, files, **kwargs)
   1524         if return_raw_response:
   1525             return resp
-> 1526         return self._handle_response(
   1527             resp=resp,
   1528             out_path=out_path,

/opt/conda/lib/python3.11/site-packages/arcgis/gis/_impl/_con/_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)
    999                     return data
   1000                 errorcode = data["error"]["code"] if "code" in data["error"] else 0
-> 1001                 self._handle_json_error(data["error"], errorcode)
   1002             return data
   1003         else:

/opt/conda/lib/python3.11/site-packages/arcgis/gis/_impl/_con/_connection.py in _handle_json_error(self, error, errorcode)
   1022 
   1023         errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
-> 1024         raise Exception(errormessage)
   1025 
   1026     def post_multipart(

Exception: Specified output format not supported.
(Error Code: 400)

Expected behavior I would expect the generation of the report to succeed with the parameters provided.

Platform (please complete the following information):