<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Timeout error (504) on batch_add of workforce assignments in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/timeout-error-504-on-batch-add-of-workforce/m-p/1101008#M6678</link>
    <description>&lt;P&gt;I'm moving data out of a dataframe and into a workforce app.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Traceback:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "crm-extractor.py", line 211, in &amp;lt;module&amp;gt;
    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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;python version: 3.7.9&lt;/P&gt;&lt;P&gt;arcgis version: 1.8.3&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;UPDATE:&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;I rearranged the script to try posting to the REST API using the requests library, but it still times out.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Sep 2021 16:52:20 GMT</pubDate>
    <dc:creator>Jesse</dc:creator>
    <dc:date>2021-09-23T16:52:20Z</dc:date>
    <item>
      <title>Timeout error (504) on batch_add of workforce assignments</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/timeout-error-504-on-batch-add-of-workforce/m-p/1101008#M6678</link>
      <description>&lt;P&gt;I'm moving data out of a dataframe and into a workforce app.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;Traceback:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "crm-extractor.py", line 211, in &amp;lt;module&amp;gt;
    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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;python version: 3.7.9&lt;/P&gt;&lt;P&gt;arcgis version: 1.8.3&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;UPDATE:&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;I rearranged the script to try posting to the REST API using the requests library, but it still times out.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 16:52:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/timeout-error-504-on-batch-add-of-workforce/m-p/1101008#M6678</guid>
      <dc:creator>Jesse</dc:creator>
      <dc:date>2021-09-23T16:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Timeout error (504) on batch_add of workforce assignments</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/timeout-error-504-on-batch-add-of-workforce/m-p/1101382#M6680</link>
      <description>&lt;P&gt;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 &amp;lt;a&amp;gt; tags, but the tag wasn't getting constructed properly. Also, according to &lt;A href="https://community.esri.com/t5/arcgis-workforce-questions/add-hyperlink-to-description-field/td-p/815840" target="_blank" rel="noopener"&gt;this post&lt;/A&gt;, 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 &amp;lt;a&amp;gt; tag, and that solved the timeout issue.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 18:06:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/timeout-error-504-on-batch-add-of-workforce/m-p/1101382#M6680</guid>
      <dc:creator>Jesse</dc:creator>
      <dc:date>2021-09-23T18:06:03Z</dc:date>
    </item>
  </channel>
</rss>

