Select to view content in your preferred language

Field calculating error - failed to connect

1461
3
03-04-2021 09:34 AM
Labels (1)
AFackler_NAPSG
Frequent Contributor

Hello everyone-

I am attempting to write my first real notebook based off a python script I wrote a while back. This script takes two layers, a "facility" layer, and a county layer, joins them by facility name, adds and calculates today's date, then appends the data to another AGOL feature layer as an archive layer. I added a date field to the facilities, so no need to add a field via code anymore. However, I am having some issues with the field calculate function in Notebooks. From my understanding, it is a connection issue, but the rest of my code works fine. I frankly have no idea where to go from here to troubleshoot. My best guess is it's throwing the error because I didn't import the field calculate tool, but if that's the case I'm still lost. Thanks in advance!!

Imports:

from pathlib import Path
import sys
from arcgis.gis import GIS, Item
from arcgis.features import FeatureLayerCollection
from arcgis.features.analysis import join_features
import datetime
from arcgis.geoanalytics.manage_data import calculate_fields

 

Field Calc:

layer=joinData.id

dateCalc = calculate_fields(input_layer=layer,
field_name="data_date",
data_type="Date",
expression="datetime.datetime.now()")

 

Output:

gaierror                                  Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/urllib3/connection.py in _new_conn(self)
    156             conn = connection.create_connection(
--> 157                 (self._dns_host, self.port), self.timeout, **extra_kw
    158             )

/opt/conda/lib/python3.6/site-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     60 
---> 61     for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
     62         af, socktype, proto, canonname, sa = res

/opt/conda/lib/python3.6/socket.py in getaddrinfo(host, port, family, type, proto, flags)
    744     addrlist = []
--> 745     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    746         af, socktype, proto, canonname, sa = res

gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

NewConnectionError                        Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    671                 headers=headers,
--> 672                 chunked=chunked,
    673             )

/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    375         try:
--> 376             self._validate_conn(conn)
    377         except (SocketTimeout, BaseSSLError) as e:

/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py in _validate_conn(self, conn)
    993         if not getattr(conn, "sock", None):  # AppEngine might not have  `.sock`
--> 994             conn.connect()
    995 

/opt/conda/lib/python3.6/site-packages/urllib3/connection.py in connect(self)
    299         # Add certificate verification
--> 300         conn = self._new_conn()
    301         hostname = self.host

/opt/conda/lib/python3.6/site-packages/urllib3/connection.py in _new_conn(self)
    168             raise NewConnectionError(
--> 169                 self, "Failed to establish a new connection: %s" % e
    170             )

NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f6b22926630>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    448                     retries=self.max_retries,
--> 449                     timeout=timeout
    450                 )

/opt/conda/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    719             retries = retries.increment(
--> 720                 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
    721             )

/opt/conda/lib/python3.6/site-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    435         if new_retry.is_exhausted():
--> 436             raise MaxRetryError(_pool, url, error or ResponseError(cause))
    437 

MaxRetryError: HTTPSConnectionPool(host='geoanalytics.arcgis.com', port=443): Max retries exceeded with url: /arcgis/rest/services/GeoAnalyticsTools/GPServer/CalculateField/submitJob (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6b22926630>: Failed to establish a new connection: [Errno -2] Name or service not known',))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/arcgis/gis/_impl/_con/_connection.py in post(self, path, params, files, **kwargs)
    676                                           cert=cert,
--> 677                                           files=files)    678         except requests.exceptions.SSLError as err:

/opt/conda/lib/python3.6/site-packages/requests/sessions.py in post(self, url, data, json, **kwargs)
    577 
--> 578         return self.request('POST', url, data=data, json=json, **kwargs)
    579 

/opt/conda/lib/python3.6/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    529         send_kwargs.update(settings)
--> 530         resp = self.send(prep, **send_kwargs)
    531 

/opt/conda/lib/python3.6/site-packages/requests/sessions.py in send(self, request, **kwargs)
    642         # Send the request
--> 643         r = adapter.send(request, **kwargs)
    644 

/opt/conda/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    515 
--> 516             raise ConnectionError(e, request=request)
    517 

ConnectionError: HTTPSConnectionPool(host='geoanalytics.arcgis.com', port=443): Max retries exceeded with url: /arcgis/rest/services/GeoAnalyticsTools/GPServer/CalculateField/submitJob (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6b22926630>: Failed to establish a new connection: [Errno -2] Name or service not known',))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
<ipython-input-14-2e9a8f03d77d> in <module>
      2                             field_name="data_date",
      3                             data_type="Date",
----> 4                             expression="datetime.datetime.now()")
/opt/conda/lib/python3.6/site-packages/arcgis/geoanalytics/manage_data.py in calculate_fields(input_layer, field_name, data_type, expression, track_aware, track_fields, time_boundary_split, time_split_unit, time_reference, output_name, gis, context, future)
    974             gpjob = _execute_gp_tool(gis, tool_name, params, param_db, return_values, _use_async, url, True, future=future)
    975             return GAJob(gpjob=gpjob, return_service=output_service)
--> 976         _execute_gp_tool(gis, tool_name, params, param_db, return_values, _use_async, url, True, future=future)
    977         return output_service
    978     except:

/opt/conda/lib/python3.6/site-packages/arcgis/geoprocessing/_support.py in _execute_gp_tool(gis, task_name, params, param_db, return_values, use_async, url, webtool, add_token, return_messages, future)
    388                 job_info = gptool._con.post(submit_url, gp_params)
    389         else:
--> 390             job_info = gptool._con.post(submit_url, gp_params)
    391         job_id = job_info['jobId']
    392         if future:

/opt/conda/lib/python3.6/site-packages/arcgis/gis/_impl/_con/_connection.py in post(self, path, params, files, **kwargs)
    684         except requests.exceptions.ConnectionError as errCE:
    685             raise requests.exceptions.ConnectionError(
--> 686                 "A connection error has occurred: %s" % errCE)    687         except requests.exceptions.InvalidHeader as errIH:
    688             raise requests.exceptions.InvalidHeader(

ConnectionError: A connection error has occurred: HTTPSConnectionPool(host='geoanalytics.arcgis.com', port=443): Max retries exceeded with url: /arcgis/rest/services/GeoAnalyticsTools/GPServer/CalculateField/submitJob (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6b22926630>: Failed to establish a new connection: [Errno -2] Name or service not known',))

 

0 Kudos
3 Replies
by Anonymous User
Not applicable

Hi Adam,

The reason you are seeing this error is because the calculate_fields is under the Geoanalytics module of the python API and requires a Geoanalytics server. If you're connected to an external GIS that might have a geoanalytics server installed, use the below command to check if your GIS supports geoanalytics.

 

 

arcgis.geoanalytics.is_supported(gis)

 

 

However, for the default GIS in Online, this will return false as geoanalytics is not supported in Online.

Josh_0-1616527828342.png

See this link for more info on the geoanalytics module of the ArcGIS Python API.
https://developers.arcgis.com/python/api-reference/arcgis.geoanalytics.toc.html#module-arcgis.geoana... 

Thanks,
Josh

0 Kudos
AFackler_NAPSG
Frequent Contributor

Thanks for your answer, @Anonymous User!

Here's the funny thing. When I put in that script, it returns "True" but still gives me the same error. Any guidance from here? And if there is no field calculate available, is there an alternative?

AdamFackler1_0-1616528882469.png

 

Thanks!

Adam

0 Kudos
NoahSlocum
Esri Contributor

Hi @AFackler_NAPSG , the reason you are still seeing this error is that arcgis.geoanalytics is not supported by https://arcgis.com, it requires a base deployment of ArcGIS Enterprise and a licensed GeoAnalytics Server to run each function. There is an issue where arcgis.geoanalytics.is_supported() will incorrectly return True in the case above, we are working on fixing this. 

If you don't have ArcGIS Enterprise and a GeoAnalytics Server you could instead try to create a Pandas DataFrame or Spatially Enabled DataFrame, add a column and calculate time using python's built-in time module, and export the DataFrame to a Feature Layer.
You could alternatively add a field directly to the layer using this example and edit your features to populate the timestamp.