Timeout error (504) on batch_add of workforce assignments

104
1
Jump to solution
4 weeks ago
Jesse
by
New Contributor II

I'm moving data out of a dataframe and into a workforce app. 

 

 

from arcgis.apps import workforce
from arcgis.gis import GIS
from arcgis.geometry import Point
import datetime

# Set up the workforce project
gis = GIS(url="https://place.maps.arcgis.com",
            username="u_name", password="pw")
layer = gis.content.search("itemID")[0] # Gives a FeatureCollection
project = workforce.Project(layer)
# Create a list of project assignments
assignments = []
for _, row in df.iterrows():
    print(f"Processing {row['Request']}...")
    # Initialize variables
    geometry = Point({
        "x": row["Longitude"],
        "y": row["Latitude"],
        "spatialReference": {"wkid": 4326}
    })
    reproj = arcgis.geometry.project(
        geometries=[geometry],
        in_sr=4326,
        out_sr=3857
    )[0]
    assignment_details = {
        "assignment_type": "Intake",
        "geometry": reproj,
        "priority": 0,
        "location": "Test",
        "status": 1,
        "description": row["Description"],
        "work_order_id": row["Request"],
        "due_date": row["Entered date"],
        "assigned_date": datetime.datetime.utcnow(),
        "worker": project.workers.get(user_id="user")
    }
    # Create workforce assignment
    assignment = workforce.Assignment(project, **assignment_details)
    assignments.append(assignment)
project.assignments.batch_add(assignments)

 

 

My understanding of 500 errors is that there's not much I can do to solve the problem, right? Still, is there something about my code that's causing a hangup?

Traceback:

 

Traceback (most recent call last):
  File "crm-extractor.py", line 211, in <module>
    project.assignments.batch_add(assignments)
  File "C:\Users\nestj1\AppData\Local\ESRI\conda\envs\publicspace_env\lib\site-packages\arcgis\apps\workforce\managers.py", line 83, in batch_add
    return add_assignments(self.project, assignments)
  File "C:\Users\nestj1\AppData\Local\ESRI\conda\envs\publicspace_env\lib\site-packages\arcgis\apps\workforce\_store\assignments.py", line 72, in add_assignments
    add_features(project.assignments_layer, features, use_global_ids)
  File "C:\Users\nestj1\AppData\Local\ESRI\conda\envs\publicspace_env\lib\site-packages\arcgis\apps\workforce\_store\utils.py", line 19, in add_features     
    response = feature_layer.edit_features(adds=feature_set, use_global_ids=use_global_ids)
  File "C:\Users\nestj1\AppData\Local\ESRI\conda\envs\publicspace_env\lib\site-packages\arcgis\features\layer.py", line 2393, in edit_features
    return self._con.post(path=edit_url, postdata=params)#, token=self._token)
  File "C:\Users\nestj1\AppData\Local\ESRI\conda\envs\publicspace_env\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 720, in post
    force_bytes=kwargs.pop('force_bytes', False))
  File "C:\Users\nestj1\AppData\Local\ESRI\conda\envs\publicspace_env\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 514, in _handle_response 
    self._handle_json_error(data['error'], errorcode)
  File "C:\Users\nestj1\AppData\Local\ESRI\conda\envs\publicspace_env\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 536, in _handle_json_error
    raise Exception(errormessage)
Exception: Your request has timed out.
(Error Code: 504)

 

python version: 3.7.9

arcgis version: 1.8.3

UPDATE:

I rearranged the script to try posting to the REST API using the requests library, but it still times out.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Jesse
by
New Contributor II

After a lot of tinkering, it turned out to be an issue with the description field. I was trying to hyperlink to a URL using <a> tags, but the tag wasn't getting constructed properly. Also, according to this post, it doesn't seem like HTML is honored in Workforce yet. I reconstructed the description to include the raw URL rather than the URL formatted into an <a> tag, and that solved the timeout issue.

View solution in original post

0 Kudos
1 Reply
Jesse
by
New Contributor II

After a lot of tinkering, it turned out to be an issue with the description field. I was trying to hyperlink to a URL using <a> tags, but the tag wasn't getting constructed properly. Also, according to this post, it doesn't seem like HTML is honored in Workforce yet. I reconstructed the description to include the raw URL rather than the URL formatted into an <a> tag, and that solved the timeout issue.

View solution in original post

0 Kudos