Skip to content

Attempt to export server logs to file fails #1071

@phaakma

Description

@phaakma

Describe the bug
After obtaining a reference to a server object, an attempt to query out some logs and export them to a file fails on two counts.

Both error messages reference this file:
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\admin_logs.py

First there is a TypeError when it attempts to open the file:
---> TypeError: open() missing required argument 'file'
The error is on line 270, and appears to be an incorrect syntax. The code current says:
---> with open(name=out_path, mode='wb') as f
when it should be:
---> with open(file=out_path, mode='wb') as f

After I manually updated this line in the file, a second TypeError occurred at line 278:
---> TypeError: a bytes-like object is required, not 'str'
I was able to resolve this issue by further altering line 270 by changing the 'wb' to 'w', as follows:
---> with open(file=out_path, mode='w') as f

As one more bonus issue that can also be resolved by amending line 270: The resulting csv on my Windows machine has extra line breaks inserted after each record. The python documentation suggests that opening the file should include explicitly setting newline='' to avoid this.
https://docs.python.org/3/library/csv.html#examples
And I was able to resolve this issue by further altering line 270 as follows:
---> with open(file=out_path, mode='w', newline='') as f

To Reproduce
I used a Notebook running inside ArcGIS Pro v2.8.1 with the following code:

from arcgis.gis import GIS
gis = GIS("home")
server = gis.admin.servers.list()[1]
logs = server.logs.query(start_time='2021-07-28T22:00:00,000', end_time='2021-07-28T21:59:00,000', export=True, out_path='c:/temp/logs.csv')

error:
First error:
image
Second error after making first code change:
image

Expected behavior
Expected to have a csv file successfully exported to a local file containing the logs.

Platform (please complete the following information):

  • OS: Windows 10
  • Python API Version: 1.8.5
  • ArcGIS Pro v2.8.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions