Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.9k stars 1.1k forks source link

Token required but not passed in the request. #1318

Closed redcican closed 2 years ago

redcican commented 2 years ago

I am trying to run this notebook, finding_routes_for_appliance_delivery_with_VRP_solve but I kept having this error:

Exception: Token required but not passed in the request.
Token required.
(Error Code: 499)

when run to the code:

# Read the csv file and convert the data to feature set
orders_df = pd.read_csv(orders_csv)
orders_sdf = pd.DataFrame.spatial.from_df(orders_df, "Address")
orders_fset = orders_sdf.spatial.to_featureset()

I tried to access Gis by:

gis = GIS(url="https://*******.maps.arcgis.com/home/", username="*****", password="******")

I don't have a pro account, and I am running my code on Google Colab. Do I need a Pro account to access this service? Or anyone can tell me how to access this service?

achapkowski commented 2 years ago

No Arcpy is not needed. What version of the API are you using?

redcican commented 2 years ago

@achapkowski arcgis-2.0.1

I followed arcgic install with minimum.

What do you mean "No Arcpy is not needed"?

achapkowski commented 2 years ago

Oops I was looking at two issues at once :) Thanks, I can not try testing it and seeing what is up.

redcican commented 2 years ago

@achapkowski so what is the most handy way to get access from Gis? If I am not a Pro user.

achapkowski commented 2 years ago

Provide a username/password into the GIS object.

GIS(username='foo', password='bar') # this connects to AGOL

See: https://developers.arcgis.com/python/guide/using-the-gis/ and https://developers.arcgis.com/python/guide/working-with-different-authentication-schemes/

redcican commented 2 years ago

@achapkowski I got the same error:

Exception Traceback (most recent call last) in () ----> 1 orders_sdf = pd.DataFrame.spatial.from_df(orders_csv, "Address") 2 orders_fset = orders_sdf.spatial.to_featureset()

5 frames /usr/local/lib/python3.7/dist-packages/arcgis/features/geo/_accessor.py in from_df(df, address_column, geocoder, sr, geometry_column) 2606 list(df[address_column]), 2607 geocoder=geocoder, -> 2608 as_featureset=True, 2609 ).sdf.sort_values(by="ResultID") 2610 piece_df.index = df.index

/usr/local/lib/python3.7/dist-packages/arcgis/geocoding/_functions.py in batch_geocode(addresses, source_country, category, out_sr, geocoder, as_featureset, match_out_of_range, location_type, search_extent, lang_code, preferred_label_values, out_fields) 1634 lang_code, 1635 preferred_label_values, -> 1636 out_fields, 1637 ) 1638

/usr/local/lib/python3.7/dist-packages/arcgis/geocoding/_functions.py in _batch_geocode(self, addresses, source_country, category, out_sr, as_featureset, match_out_of_range, location_type, search_extent, lang_code, preferred_label_values, out_fields) 451 if out_fields is not None: 452 params["outFields"] = out_fields --> 453 resp = self._con.post(url, params) 454 if resp is not None and as_featureset: 455 sr = resp["spatialReference"]

/usr/local/lib/python3.7/dist-packages/arcgis/gis/_impl/_con/_connection.py in post(self, path, params, files, **kwargs) 1410 file_name=file_name, 1411 try_json=try_json, -> 1412 force_bytes=kwargs.pop("force_bytes", False), 1413 ) 1414

/usr/local/lib/python3.7/dist-packages/arcgis/gis/_impl/_con/_connection.py in _handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key) 898 return data 899 errorcode = data["error"]["code"] if "code" in data["error"] else 0 --> 900 self._handle_json_error(data["error"], errorcode) 901 return data 902 else:

/usr/local/lib/python3.7/dist-packages/arcgis/gis/_impl/_con/_connection.py in _handle_json_error(self, error, errorcode) 921 922 errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")" --> 923 raise Exception(errormessage) 924 925 def post_multipart(

Exception: Token required but not passed in the request. Token required. (Error Code: 499)

achapkowski commented 2 years ago

In 2.1.0, which is released in Early Q1 of 2023, we cannot reproduce the issue, I am making this as fixed in a future release. Also we cannot reproduce this in 2.0.1, make your credentials are incorrect.