Hi All for the past 8 weeks i have been running a script that populates workforce with assignments from a csv published as a feature to ArcGIS online using python it worked every day until today when i was met with an error.
strptime() argument 1 must be str, not int Failed to execute (Add Assignments)
from datetime import datetime
#Append updated information
assignments = []
for feature in features:
assignments.append(
workforce.Assignment(
project,
geometry=feature.geometry,
location=feature.attributes["location"],
due_date=datetime.strptime(feature.attributes["Due_Date"], '%d/%m/%Y %H:%M:%S'),
description=feature.attributes["description"],
priority=2,
assignment_type=feature.attributes["AssignmentTXT"],
status="unassigned",
work_order_id=feature.attributes["WorkOrderReference"]
)
)
project.assignments.batch_add(assignments)
the error is relating to the date field, i have changed nothing in my script. i uploaded the csv to Arcgis online published it as a feature and then used it to populate the assignments. Prior to this the due date was always recognized as a string but today Arcgis online recognized it as a date. Why would this suddenly start happening has something change with the way a csv is published to Arcgis online. i know i can just use the date field now but i am just curious as to why all of a sudden it changed.
Are you sure something didn't change in the formatting of the CSV? Could the date field used to have quotes around it and now it doesn't?
to fix I would just wrap the due date in a string function.
str(feature.attributes["Due_Date"])
Hi Joshua/Clay
thanks for your response. the issue seems to be intermittant sometimes its a date sometimes a string.
No they did not have quotes around them .
Clay do you think will this work for both scenarios i.e the field type is a string or a date format. The date format would be a unix timestamp.
I think Clay Donaldson's suggestion is the best path forward. In terms of whether it will work, no better way to find out then trying it.
In terms of why it is read as a date sometimes and a string other times, I am still going back to the program creating the CSV. How is the CSV file being created?
It could be the file is being read differently between different Python versions. Are you running the code on the same machine or on different machines with Python 2.x on some machines and Python 3.x on others.
Hi Joshua
I tried it with the string function and this time the script returned a date as opposed to yesterday where it returned a string and it failed with the following error
in terms of python versions i wrote the code in jupyter notebook and i am running it in arcgis pro but as far as i can see they are both python 3. Is there a particular module in pro that may be acting differently?
I was more concerned about a Python 2/3 issue than Jupyter/Pro. That said, if it consistently gives different results when run in the two environments, then something is definitely different. Are the results the same when run repeatedly from the same environment?
They were the same for several weeks it worked fine in both . I did have a cloned environment in arcgis pro that i was using, which i removed. Would that have caused an issue . My current solution is adding an additional string field and calculating the date into it , i am now using that to update the Assignment which seems to work consistently.