Can't figure out create locator tool for arcpy

Jump to solution
a month ago
New Contributor

Hello everyone, 
I'm running Pro 3.1.2 and i'm working on a python script that automates the creation of an mmpk for use in field maps. Currently, the script pulls data from a server and adds that to a map. I hope to use those layers directly from the contents pane to create the mmpk. 

Haven't been able to get passed the create locator tool for the mmpk. I'm looking to set up a locator with one of the layers (a road layer) but whenever I run the script, I get this error: 
Error creating locator: Failed to execute. Parameters are not valid.
ERROR 002790: Every Table requires a Role.

I'd appreciate any insights I can get on this. Thank you!

The code looks like this: 

# List of data source URLs
serverData = [r"https://serverdata",

# Open Pro Project
aprx ="pathToProject")

# Create a new disposable map
map = aprx.createMap("MMPK", "MAP")
print(, "has been added")

# Get rid of basemap layer from map
basemap = map.listLayers()
for i in basemap:
    print(, "is an active layer")
    if == "Topographic":

# Add Data Layers from Server to map
layers = []
for data in serverData:
        layer = map.addDataFromPath(data)
        print(f"Added layer from {data}")
    except Exception as e:
        print(f"Error adding layer from {data}: {e}")

# Create Locator
lang = "ENG"
output = r"saveLocatorPath"
road_layer = layers[1]
fieldMap = "StreetAddress.HOUSE_NUMBER_FROM_LEFT",road_layer,".L_LADD",\

refData = road_layer, "StreetAddress"

    arcpy.geocoding.CreateLocator(country_code="CAN", primary_reference_data=refData, field_mapping=fieldMap,  out_locator=output, language_code=lang)
    print("Locator created successfully.")
except Exception as e:
    print(f"Error creating locator: {e}")
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Occasional Contributor

Try refData = road_layer + " StreetAddress"

#CLE #sloth

View solution in original post

3 Replies
Occasional Contributor

Try refData = road_layer + " StreetAddress"

#CLE #sloth
New Contributor

Thank you very much. This seemed to ease up my error, paired with Blake's response. It could not register the layer and role with my initial setup. 

0 Kudos
MVP Regular Contributor

I think your fieldMap is incorrect. The error: "Every table requires a role" refers to the role that is also configured within the field_mapping. If you run the tool manually in ArcGIS Pro, then go to the geoprocessing history tab in the Catalog pane, you can right click on the tool result and copy as Python command. Then paste that into your code editor so you can see the formatting of everything. That's what I did here and this was what I got.


fieldMap = [
    "StreetAddress.HOUSE_NUMBER_FROM_LEFT 'road_layer'.L_LADD",
    "StreetAddress.HOUSE_NUMBER_TO_LEFT 'road_layer'.L_HADD",
    "StreetAddress.HOUSE_NUMBER_FROM_RIGHT 'road_layer'.R_LADD",
    "StreetAddress.HOUSE_NUMBER_TO_RIGHT 'road_layer'.R_HADD",
    "StreetAddress.HOUSE_NUMBER_FROM_RIGHT 'road_layer'.R_LADD",
    "StreetAddress.PARITY_LEFT 'road_layer'.L_PARITY",
    "StreetAddress.PARITY_RIGHT 'road_layer'.R_PARITY",
    "StreetAddress.STREET_NAME 'road_layer'.NAME",
    "StreetAddress.STREET_SUFFIX_TYPE 'road_layer'.SFX",
    "StreetAddress.STREET_SUFFIX_DIR 'road_layer'.DIR",
    "StreetAddress.FULL_STREET_NAME 'road_layer'.FULL_NAME"