Python project call crashing out

1269
6
10-03-2021 04:20 AM
IanHamilton2
New Contributor III

I am unable to get this call to project a point to complete.

I am connecting to an enterprise portal from an arcgis install at home through Jupiter labs. I have been successfully connecting using a client  Id I created through the enterprise portal web interface. See below. I am unable to project any data (other calls to get featureLayer etc all have worked so far). Exceptions attached. It appears that the code is trying to guess my connection, but should already have this information in the gis I create.

Would anyone have any idea what is going wrong?

from arcgis import geometry
from arcgis.geometry import Point, project, find_transformation

from arcgis.gis import GIS

gis = GIS("https://myurl.com/portal",client_id="xyz")

ptwebm = Point({"x" : 17041106.13569748, "y" : -3183137.706970891})

result = project(geometries=[ptwebm],in_sr = 3857,out_sr = 4326,gis=gis)

 

Thanks,

Ian

0 Kudos
6 Replies
DavidPike
MVP Frequent Contributor

Hi Ian,  Your attached image is unfortunately unreadable (for me at-least).

0 Kudos
MehdiPira1
Esri Contributor

@IanHamilton2 ,

I don't why you're getting this error as the attached screenshot is small and blurry.

You could also try the normal log into Portal and see if it works out the projection:

gis = GIS("https://myurl.com/portal", "username", "password", verify_cert=False)

 

0 Kudos
IanHamilton2
New Contributor III

Sorry about the log.

Thanks for your help. I have tried using my username and password but there is 2 factor authentication to contend with  - from home I am not getting a code. So I used the client id method instead.

I guess this is a bug, otherwise why would I be able to connect and access feature services etc but no be able to use some of the API 

 here us the text

 

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in __init__(self, url, gis)
    329                     try:
--> 330                         self._token = self._con.generate_portal_server_token(url)
    331                     except Exception as e:  # GUESSED Auth Wrong, try anonymously

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in generate_portal_server_token(self, serverUrl, expiration)
   1738         else:
-> 1739             resp = self.post(   1740                 path=self._token_url, postdata=postdata, ssl=True, add_token=False

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in post(self, path, params, files, **kwargs)
   1040         retry_count = 0
-> 1041         return self._handle_response(   1042             resp=resp,

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes)
    594                 errorcode = data["error"]["code"] if "code" in data["error"] else 0
--> 595                 self._handle_json_error(data["error"], errorcode)
    596             return data

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in _handle_json_error(self, error, errorcode)
    617         errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
--> 618         raise Exception(errormessage)
    619 

Exception: client_id not specified
(Error Code: 400)

During handling of the above exception, another exception occurred:

RequestException                          Traceback (most recent call last)
<ipython-input-6-63ef118dd7a8> in <module>
      1 ptwebm = Point({"x" : 17041106.13569748, "y" : -3183137.706970891})
----> 2 result = project(geometries=[ptwebm],in_sr = 3857,out_sr = 4326,gis=gis)

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/geometry/functions.py in project(geometries, in_sr, out_sr, transformation, transform_forward, gis, future)
    947     if gis is None:
    948         gis = arcgis.env.active_gis
--> 949     return gis._tools.geometry.project(    950         geometries, in_sr, out_sr, transformation, transform_forward, future=future
    951     )

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in geometry(self)
  17106             else:
  17107                 svcurl = self._gis.properties["helperServices"]["geometry"]["url"]
> 17108             self._geometry = _GeometryService(svcurl, self._gis)
  17109             return self._geometry
  17110         except KeyError:

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in __init__(self, url, gis)
  15420 
  15421     def __init__(self, url, gis=None):
> 15422         super(_GeometryService, self).__init__(url, gis)
  15423 
  15424     @classmethod

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in __init__(self, url, gis)
    352                             from requests.exceptions import RequestException
    353 
--> 354                             raise RequestException(str(e))
    355                 else:
    356                     self._token = self._con.token

RequestException: client_id not specified
(Error Code: 400)

 

0 Kudos
IanHamilton2
New Contributor III

My apologies. The call with user name and password does not work for me as there is 2 factor identification at work and I am trying to connect from home.

here is the log

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in __init__(self, url, gis)
    329                     try:
--> 330                         self._token = self._con.generate_portal_server_token(url)
    331                     except Exception as e:  # GUESSED Auth Wrong, try anonymously

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in generate_portal_server_token(self, serverUrl, expiration)
   1738         else:
-> 1739             resp = self.post(   1740                 path=self._token_url, postdata=postdata, ssl=True, add_token=False

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in post(self, path, params, files, **kwargs)
   1040         retry_count = 0
-> 1041         return self._handle_response(   1042             resp=resp,

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes)
    594                 errorcode = data["error"]["code"] if "code" in data["error"] else 0
--> 595                 self._handle_json_error(data["error"], errorcode)
    596             return data

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in _handle_json_error(self, error, errorcode)
    617         errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
--> 618         raise Exception(errormessage)
    619 

Exception: client_id not specified
(Error Code: 400)

During handling of the above exception, another exception occurred:

RequestException                          Traceback (most recent call last)
<ipython-input-6-63ef118dd7a8> in <module>
      1 ptwebm = Point({"x" : 17041106.13569748, "y" : -3183137.706970891})
----> 2 result = project(geometries=[ptwebm],in_sr = 3857,out_sr = 4326,gis=gis)

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/geometry/functions.py in project(geometries, in_sr, out_sr, transformation, transform_forward, gis, future)
    947     if gis is None:
    948         gis = arcgis.env.active_gis
--> 949     return gis._tools.geometry.project(    950         geometries, in_sr, out_sr, transformation, transform_forward, future=future
    951     )

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in geometry(self)
  17106             else:
  17107                 svcurl = self._gis.properties["helperServices"]["geometry"]["url"]
> 17108             self._geometry = _GeometryService(svcurl, self._gis)
  17109             return self._geometry
  17110         except KeyError:

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in __init__(self, url, gis)
  15420 
  15421     def __init__(self, url, gis=None):
> 15422         super(_GeometryService, self).__init__(url, gis)
  15423 
  15424     @classmethod

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in __init__(self, url, gis)
    352                             from requests.exceptions import RequestException
    353 
--> 354                             raise RequestException(str(e))
    355                 else:
    356                     self._token = self._con.token

RequestException: client_id not specified
(Error Code: 400)
0 Kudos
IanHamilton2
New Contributor III

Sorry about the log.

Thanks for your help. I have tried using my username and password but there is 2 factor authentication to contend with  - from home I am not getting a code. So I used the client id method instead.

I guess this is a bug, otherwise why would I be able to connect and access feature services etc but no be able to use some of the API 

 here us the text

 

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in __init__(self, url, gis)
    329                     try:
--> 330                         self._token = self._con.generate_portal_server_token(url)
    331                     except Exception as e:  # GUESSED Auth Wrong, try anonymously

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in generate_portal_server_token(self, serverUrl, expiration)
   1738         else:
-> 1739             resp = self.post(   1740                 path=self._token_url, postdata=postdata, ssl=True, add_token=False

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in post(self, path, params, files, **kwargs)
   1040         retry_count = 0
-> 1041         return self._handle_response(   1042             resp=resp,

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes)
    594                 errorcode = data["error"]["code"] if "code" in data["error"] else 0
--> 595                 self._handle_json_error(data["error"], errorcode)
    596             return data

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py in _handle_json_error(self, error, errorcode)
    617         errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
--> 618         raise Exception(errormessage)
    619 

Exception: client_id not specified
(Error Code: 400)

During handling of the above exception, another exception occurred:

RequestException                          Traceback (most recent call last)
<ipython-input-6-63ef118dd7a8> in <module>
      1 ptwebm = Point({"x" : 17041106.13569748, "y" : -3183137.706970891})
----> 2 result = project(geometries=[ptwebm],in_sr = 3857,out_sr = 4326,gis=gis)

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/geometry/functions.py in project(geometries, in_sr, out_sr, transformation, transform_forward, gis, future)
    947     if gis is None:
    948         gis = arcgis.env.active_gis
--> 949     return gis._tools.geometry.project(    950         geometries, in_sr, out_sr, transformation, transform_forward, future=future
    951     )

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in geometry(self)
  17106             else:
  17107                 svcurl = self._gis.properties["helperServices"]["geometry"]["url"]
> 17108             self._geometry = _GeometryService(svcurl, self._gis)
  17109             return self._geometry
  17110         except KeyError:

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in __init__(self, url, gis)
  15420 
  15421     def __init__(self, url, gis=None):
> 15422         super(_GeometryService, self).__init__(url, gis)
  15423 
  15424     @classmethod

~/opt/anaconda3/lib/python3.8/site-packages/arcgis/_impl/tools.py in __init__(self, url, gis)
    352                             from requests.exceptions import RequestException
    353 
--> 354                             raise RequestException(str(e))
    355                 else:
    356                     self._token = self._con.token

RequestException: client_id not specified
(Error Code: 400)

 

0 Kudos
IanHamilton2
New Contributor III

Apologies, here is another attempt. I cannot log in using a user and password as there is 2 factor authentication enabled on my account. This is not sending a code when trying to work from home, with or without a certificate.

0 Kudos