Select to view content in your preferred language

The network.analysis.generate_origin_destination_cost_matrix reported a 500 error if the origins or destinations is more than 300 points

2052
10
08-01-2023 07:39 PM
JunzheZhang
Emerging Contributor
To repo this case:
1. Build a random feature set with more than 300 points in Pro
2. Publish it into Enterprise
3. Run the following code with the url of the published feature
4. You will see the error message

If the number of points is less than 300, the code should work. 

Here is my code:
from arcgis.gis import GIS
from arcgis.features import FeatureLayer, Feature, FeatureSet, FeatureCollection, use_proximity

username=''
password=''
gis = GIS('', username, password, verify_cert=False, set_active=True)

import arcgis.network as network
origins=FeatureLayer('')
destinations=FeatureLayer('')
result1 = network.analysis.generate_origin_destination_cost_matrix(origins=origins, destinations=destinations, gis=gis)

Here is the error message:
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\geoprocessing\_support.py in _analysis_job_results(gptool, task_url, job_info, job_id)
    304                 try:
--> 305                     param_result = gptool._con.get(
    306                         result_url, params, token=gptool._token

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in get(self, path, params, **kwargs)
    870             return resp
--> 871         return self._handle_response(
    872             resp,

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)
   1007                 errorcode = data["error"]["code"] if "code" in data["error"] else 0
-> 1008                 self._handle_json_error(data["error"], errorcode)
   1009             return data

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in _handle_json_error(self, error, errorcode)
   1030         errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
-> 1031         raise Exception(errormessage)
   1032 

Exception: Error getting result parameter
(Error Code: 500)

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_15924\8243387.py in <cell line: 5>()
      3 origins=FeatureLayer('https://arcgis.reyesholdings.com/server/rest/services/Hosted/test_OD/FeatureServer/0')
      4 destinations=FeatureLayer('https://arcgis.reyesholdings.com/server/rest/services/Hosted/test_OD/FeatureServer/0')
----> 5 result1 = network.analysis.generate_origin_destination_cost_matrix(origins=origins, destinations=destinations, 
      6                                                                        gis=gis)

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\network\_od.py in generate_origin_destination_cost_matrix(origins, destinations, travel_mode, time_units, distance_units, analysis_region, number_of_destinations_to_find, cutoff, time_of_day, time_zone_for_time_of_day, point_barriers, line_barriers, polygon_barriers, uturn_at_junctions, use_hierarchy, restrictions, attribute_parameter_values, impedance, origin_destination_line_shape, save_output_network_analysis_layer, overrides, time_impedance, distance_impedance, output_format, gis, future)
    945     if future:
    946         return job
--> 947     return job.result()
    948 
    949 

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\geoprocessing\_job.py in result(self)
    234         elif self._is_ortho:
    235             return self._process_ortho(self._future.result())
--> 236         return self._future.result()
    237 
    238     def _process_ortho(self, result):

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\concurrent\futures\_base.py in result(self, timeout)
    444                     raise CancelledError()
    445                 elif self._state == FINISHED:
--> 446                     return self.__get_result()
    447                 else:
    448                     raise TimeoutError()

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\concurrent\futures\_base.py in __get_result(self)
    389         if self._exception:
    390             try:
--> 391                 raise self._exception
    392             finally:
    393                 # Break a reference cycle with the exception in self._exception

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\concurrent\futures\thread.py in run(self)
     56 
     57         try:
---> 58             result = self.fn(*self.args, **self.kwargs)
     59         except BaseException as exc:
     60             self.future.set_exception(exc)

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\geoprocessing\_support.py in _future_op(gptool, task_url, job_info, job_id, param_db, return_values, return_messages)
    321 
    322     job_info = _analysis_job_status(gptool, task_url, job_info)
--> 323     resp = _analysis_job_results(gptool, task_url, job_info, job_id)
    324 
    325     # ---------------------async-out---------------------#

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\geoprocessing\_support.py in _analysis_job_results(gptool, task_url, job_info, job_id)
    307                     )
    308                 except:
--> 309                     param_result = gptool._con.get(result_url, params)
    310 
    311                 job_value = param_result.get("value")

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in get(self, path, params, **kwargs)
    869         if return_raw_response:
    870             return resp
--> 871         return self._handle_response(
    872             resp,
    873             file_name,

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)
   1006                     return data
   1007                 errorcode = data["error"]["code"] if "code" in data["error"] else 0
-> 1008                 self._handle_json_error(data["error"], errorcode)
   1009             return data
   1010         else:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py in _handle_json_error(self, error, errorcode)
   1029 
   1030         errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
-> 1031         raise Exception(errormessage)
   1032 
   1033     def post_multipart(

Exception: Error getting result parameter
(Error Code: 500)
Tags (2)
0 Kudos
10 Replies
MaxZeng
Esri Contributor

Hey Junzhe,

Good to hear from you! 

Quick question about the failure you ran into, I think you are using ArcGIS Python API with your ArcGIS Enterprise? One thing you could try is to increase the heap size of the OD Cost Matrix GPServer service and see whether it works for your. Here is the documentation.

If it doesn't work, let me know and I can provide some other suggestions.

Also, what is the version of ArcGIS Python API you are using?

Thanks,

Max

0 Kudos
JunzheZhang
Emerging Contributor

Hi Max, 

Hope everything went well.

Thanks for reaching out. I increased the heap size and it works !!

Btw, I have one question for this class (ODCostMatrixLayer

What is the URL in class arcgis.network.ODCostMatrixLayer(urlgis=None) for?

Thanks. 

0 Kudos
MaxZeng
Esri Contributor

Hey Junzhe,

Great to know it works! The url in the class, is used to provide a url to the synchronous OD Cost Matrix service on the federated server of the portal. 

Thanks,

Max

0 Kudos
MaxZeng
Esri Contributor

Hey Junzhe,

One other thing worth trying, could you enable logging to debug level so we can get more details?

import logging
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
root.addHandler(handler)

 

And please post the results of that so we can get more details about why the POST request failed.

0 Kudos
JunzheZhang
Emerging Contributor

@MaxZeng Hi Max, sorry for bothering you.

How can I specify 'Name' for the origins and destinations feature set?

The help link https://developers.arcgis.com/python/api-reference/arcgis.network.analysis.html#generate-origin-dest...

said "The name can be an unique identifier for the origin."

Does it mean to append a new attribute into the feature set?

0 Kudos
MaxZeng
Esri Contributor

Hey @JunzheZhang ,

Depending on where your feature set is originally from, there are different ways to do it, if your feature set is coming from feature service, then it might be easiest to just add to the service itself. Otherwise, you can get the feature set, convert to dict, add "Name" in "attributes" for each record, and then convert that back to feature set.

The syntax example in the rest API doc might be more clear, it shows feature set with that Name attribute for each record.

https://developers.arcgis.com/rest/network/api-reference/origin-destination-cost-matrix-service.htm#...

0 Kudos
JunzheZhang
Emerging Contributor

Thanks @MaxZeng 

0 Kudos
JunzheZhang
Emerging Contributor

@MaxZeng Sorry for bothering you again. 

The network analysis tools kept reporting this error. Then, I restarted the NA servers. 

JunzheZhang_1-1701368286329.png

However, it reported this error. Do you know how to handle it? Thanks.

JunzheZhang_0-1701368267860.png

 

 

0 Kudos
MaxZeng
Esri Contributor

@JunzheZhang , ArcGIS Pro uses geoprocessing service, so the failure has nothing to do with not able to restart your NAServer service. You can go to server log and see whether that job ID shows you any message. You could also construct the job url and look at the messages. URL will be something like https://<gpservice-url>/FindRoutes/jobs/[jobID]

If your NetworkAnalysis geoprocessing service is not Info level message, change to Info level message and rerun the analysis, that will have more log messages when you look at the job using that url above.

For the NAServer issue, not sure what is going on. Since the service was fine but have issue after restarting, not sure whether it is data access issue or something like that. See whether the server logs show more. 

0 Kudos