arcgis-python-api icon indicating copy to clipboard operation
arcgis-python-api copied to clipboard

Issues with datetime imports; arcgis python API is overwriting the import causing a runtime exception

Open pfoppe opened this issue 1 year ago • 1 comments

Describe the bug "datetime" module is imported when creating a "GIS" object. This datetime import is overwriting the main code datetime import causing errors such as "AttributeError: module 'datetime' has no attribute 'strftime'"

To Reproduce Steps to reproduce the behavior:

Run this code first to show datetime behavior without the arcgis python API:

from datetime import datetime
dt=datetime.strftime(datetime.now(),"%Y%m%d_%H%M%S")
print(dt)

The output will be a datetime stamp in the specified format

Run this code second to show datetime behavior is corrupted when using the arcgis python API:

from datetime import datetime
from arcgis import GIS
mygis=GIS("pro")
dt=datetime.strftime(datetime.now(),"%Y%m%d_%H%M%S")
print(dt)

error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'datetime' has no attribute 'strftime'

Screenshots N/A

Expected behavior When creating an arcgis python API object, it should not corrupt my previous imports

Platform (please complete the following information):

  • OS: Windows 10
  • Browser: N/A
  • Python API Version:2.1.0.2

Additional context

It appears the 'datetime' module is imported after creation of the "GIS" object.

Quick fix around this issue...

#Fix Esri bug
try:
    dt=datetime.strftime(datetime.now(),"%Y%m%d_%H%M%S")
except:
    dt=datetime.datetime.strftime(datetime.datetime.now(),"%Y%m%d_%H%M%S")

pfoppe avatar Feb 27 '24 04:02 pfoppe

@pfoppe I can confirm this is occurring as well when login is "pro" We will look into this.

Workaround for now can be your try/except or to import datetime after you login.

nanaeaubry avatar Feb 27 '24 09:02 nanaeaubry