Esri / arcgis-python-api

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

Error when trying to list Usage Reports #450

Closed l84tahoe closed 3 years ago

l84tahoe commented 5 years ago

When trying to list usage reports using the Python API against a 10.6.1 federated hosting server I receive the error quote_from_bytes() expected bytes from \conda\envs\gis\lib\urllib\parse.py I also receive this error when trying to create a quick report.

achapkowski commented 5 years ago

@l84tahoe Please provide reproducible code and arcgis api version.

Thank you

l84tahoe commented 5 years ago

@achapkowski API 1.6.1

from arcgis.gis import GIS from arcgis.gis import admin gis = GIS("https://portal.com/portal","userName") serverList = gis.admin.servers.list() server1 = serverList[0] usageReports = server1.usage.list() Print(usageReports)

l84tahoe commented 5 years ago

Also we do use IWA as our authentication.

achapkowski commented 5 years ago

@l84tahoe I'll take a look. Thanks

l84tahoe commented 5 years ago

@achapkowski Here is the console output:


TypeError Traceback (most recent call last)

in 1 serverList = gis.admin.servers.list() 2 server1 = serverList[0] ----> 3 usageReports = server1.usage.list() 4 usageReports ~\AppData\Local\ESRI\conda\envs\gis\lib\site-packages\arcgis\gis\server\admin\_usagereports.py in list(self) 68 if isinstance(self.properties['metrics'], list): 69 for r in self.properties['metrics']: ---> 70 url = self._url + "/%s" % six.moves.urllib.parse.quote(r['reportname']) 71 self._reports.append(Report(url=url, 72 gis=self._con)) ~\AppData\Local\ESRI\conda\envs\gis\lib\urllib\parse.py in quote(string, safe, encoding, errors) 787 if errors is not None: 788 raise TypeError("quote() doesn't support 'errors' for bytes") --> 789 return quote_from_bytes(string, safe) 790 791 def quote_plus(string, safe='', encoding=None, errors=None): ~\AppData\Local\ESRI\conda\envs\gis\lib\urllib\parse.py in quote_from_bytes(bs, safe) 812 """ 813 if not isinstance(bs, (bytes, bytearray)): --> 814 raise TypeError("quote_from_bytes() expected bytes") 815 if not bs: 816 return '' TypeError: quote_from_bytes() expected bytes
achapkowski commented 5 years ago

what version of arcgis server?

l84tahoe commented 5 years ago

10.6.1

BrettFrahm commented 5 years ago

Just came here to create the same issue. Below is the text from the ESRI support ticket I just created. I'm on API version 1.5.3 with a 10.6.1 server.

I am attempting to run my server reports through the ArcGIS Python API and I keep gettings the following error. Traceback (most recent call last): File "G:/Data/GISAutomation/Python/Py3.x/Dev - To Do/Dev-ManageServer.py", line 35, in usage_reports = Traditional.usage.list() File "C:\Users*\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\gis\server\admin_usagereports.py", line 70, in list url = self._url + "/%s" % six.moves.urllib.parse.quote(r['reportname']) File "C:\Users*\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\urllib\parse.py", line 789, in quote return quote_from_bytes(string, safe) File "C:\Users***\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\urllib\parse.py", line 814, in quote_from_bytes raise TypeError("quote_from_bytes() expected bytes") TypeError: quote_from_bytes() expected bytes

This is from simply trying to run the below code. portal = api.GIS("https://gis.trpdmn.org/portal", "*", "****") traditional_url = 'https://gis.trpdmn.org/traditional/admin' Traditional = server.Server(traditional_url, portal) usage_reports = Traditional.usage.list() print(usage_reports)

BrettFrahm commented 5 years ago

@achapkowski & @l84tahoe,

I found a solution that worked for me. I went into my server admin's usage report area (server url/admin/usagereports) and found that there were a few reports that had really long # names (ex: 123098345098). I deleted those reports and my code is now working.

I remember that I was playing with a code example I saw on (managing-your-gis-servers) that generates a quick report.

data = server1.usage.quick_report(since="LAST_MONTH", metrics="RequestCount") data['report'].keys()

If I'm remembering correctly, then these reports I deleted may have been generated from this quick_report meaning that they are incompatible with usage.list(). Hope that works for you. Let me know if you need any more info from me.

achapkowski commented 3 years ago

Is this still an issue using the latest version of the ArcGIS API for Python?

l84tahoe commented 3 years ago

@achapkowski I have changed organizations since creating this issue. With the newest API I no longer get the error I was experiencing before. But I am just getting a link to the usage report params. I guess I just need to append /data to the end of the URL to get the data. There might be another built in method, but I haven't had to use the usage reports since my change. But will most likely come across this again once I have Enterprise set up fully at my new org.