Python Script Error 001272 code: 00102

02-10-2021 11:03 AM
Labels (1)
Occasional Contributor II

Hey all,

I am attempting to use a Python script in ArcGIS Pro to overwrite a feature layer in AGOL. I want to use this script so that updates will be uploaded to AGOL nightly. I'm a newb when it comes to programming. I got this script from Kevin Himba (

I am currently getting an error code:

"ERROR 001272: Analyzer errors were encountered ([{"code":"00102","message":"Map does not contain a required layer type for web feature layer","object":"Recreation Asset Inventory"}]).
Failed to execute (StageService)."

One strange thing about the error is that the "Recreation Asset Inventory" is not even part of the script or the project I'm working in. It's a completely different feature layer.

Any ideas on how to proceed?


Thanks !





0 Kudos
11 Replies
MVP Emeritus

Perhaps you could provide the script in its entirety.  It seems that the script is calling an aprx, and my guess is that aprx has the  "Recreation Asset Inventory" feature layer in it.

That should just about do it....
0 Kudos
Esri Esteemed Contributor

Hi @JoshBillings ,

Try the below script instead:

A little easier to configure in my opinion.

Occasional Contributor II

Hey Jake,

Thanks for the recommendation. I am configuring this and trying to run the script. 

I am now getting an error as "UnboundLocalError: local variable 'code' referenced before assignment."

The error references: AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\gis\_impl\_con\", line 1276, in _oauth_token


Partial Code for

if soup.title is not None:
     if 'SUCCESS' in soup.title.string:
          code = soup.title.string[len('SUCCESS code='):]

oauth = OAuth2Session(self._client_id,
if code is None:
     raise Exception("Could not generate a token.")
self._create_time =
token_info = oauth.fetch_token(tu, code=code, verify=False, include_client_id=True,
self._refresh_token = token_info['refresh_token']
self._token = token_info['access_token']
self._expiration = token_info['expires_in']/60 - 2

return self._token
return None


Tried to make the 'code' variable a global variable as noted here ( but it didn't work.


Any suggestions?

0 Kudos
Esri Esteemed Contributor

@JoshBillingsmake sure your username is correct.  It is case sensitive.  Also, can you X out your password and send a screen shot of how you have the Variables section configured?

0 Kudos
Occasional Contributor II

Variables screenshot below:


I had to add a client_id to get around sign-in errors.

0 Kudos
Esri Esteemed Contributor

@JoshBillingsit looks like you are trying to authenticate with an Enterprise account, which won't work for this script.  Looks like you have a client ID.  If you have a client Secret as well, you could create a token.  Ex:


from arcgis import GIS
import requests, json

# Variables
username = 'joshuabi@CITYOFWS.ORG_CoWS'                                # AGOL username
clientId = "PAtQ6cf8UNmLthcm"                                          # AGOL App ID
clientSecret = "********"                                              # AGOL App Secret
fc = r"C:\Projects\Data.gdb\CustomerData"                              # Path to Feature Class
fsItemId = "c0e41f90407043a2b4ae6b2761c496db"                          # Feature Service Item ID to update

# Generate Token
params = {
    'client_id': clientId,
    'client_secret': clientSecret,
    'grant_type': "client_credentials",
request = requests.get('', params=params)
response = request.json()
token = response["access_token"]

# Create GIS object
gis = GIS('', token=token, verify_cert=False)
New Contributor II

@JakeSkinner , I have a similar script I'm building for overwriting a feature layer. I like the suggestion you have shared, but I wonder if this could be simplified much further by using the overwrite method shown here: 

I also wonder if it's possible to use a layer from a map in ArcGIS Pro as the input for the overwrite.

Any suggestions going this route would be helpful.

0 Kudos
Esri Esteemed Contributor

@JoeMagnottaI recommend using the following script rather than performing an overwrite of the feature service:

New Contributor II

Thank you @JakeSkinner . I ended up using arcpy, looping through a list of layers in a map to complete the overwrite. 



import arcpy

wrkspc = 'C:\\somePath'

myMap = 'someMap'

aprx ="someProject.aprx")
m = aprx.listMaps(myMap)[0]

for lyr in m.listLayers():

    sddraft = wrkspc + + '.sddraft'
    sd = wrkspc + + '.sd', sddraft,, 
                                  'MY_HOSTED_SERVICES', 'FEATURE_ACCESS', 
    arcpy.StageService_server(sddraft, sd)
    arcpy.UploadServiceDefinition_server(sd, 'My Hosted Services')




This will publish/overwrite a separate feature service for every layer in a map. I like it because of its brevity and the ability to promote symbology changes and queries from the map.

I'll give the truncate method a shot. It seems compelling. Thanks!

0 Kudos