Select to view content in your preferred language

Geocodeing in Python batch failing

1816
8
Jump to solution
06-27-2017 09:04 AM
EricAnderson14
Occasional Contributor

So I ran the 'Geocode Address' tool in ArcMap and it ran fine geocoding some addresses in an excel spreadsheet. I then went to 'Geoprocessing' and then 'Results' and did a 'Copy as python snippet'. I then placed the code in the 'Python' window that can be launched from the 'Geoprocessing' menu of ArcMap, I added the needed Import and Environment information to the Python window and ran the process, which also ran fine and geocoded my addresses. However, when I include the exact same code in a file with a '.py' suffix and try to run it, it fails every time with a message of "python.exe has stopped working - A problem caused the program to stop working correctly. Please close the program."

The code I am trying to run looks like the following:

# Import system modules
import arcpy
from arcpy import env
env.workspace = "C:\Users\A_eric.anderson\Documents\ArcGIS\Default.gdb"

arcpy.GeocodeAddresses_geocoding(in_table="C:/Users/Public/Documents/Geocoding/Addresses_To_Geocode.xlsx.xls/Excel_Destination", address_locator="D:/StreetMapPremium_R1_2017/Locators/USA_LocalComposite", in_address_fields="Address Street VISIBLE NONE;City City VISIBLE NONE;State State VISIBLE NONE;ZIP_Code ZIPCode VISIBLE NONE", out_feature_class="C:/Users/A_eric.anderson/Documents/ArcGIS/Default.gdb/Excel_Destination_GeocodeAdd4", out_relationship_type="STATIC")

Any insight on what the problem might be, would be greatly appreciated.

Thanks!

- Eric -

0 Kudos
1 Solution

Accepted Solutions
EricAnderson14
Occasional Contributor

Hi there Arjun,

Unfortunately, first level support wasn't able to fix my problem, but through their help, they un-intentionally pointed me in the right direction for an alternative. I was trying to process a large (30,000 row) excel spreadsheet. It worked fine in ArcMap, as well as ArcPy being run from ArcMap. However, when I tried to run it through the command prompt, it failed. What I eventually figured out was that if I converted my Excel spreadsheet to a CSV file, the python script would run fine from the command line.

I tried to express to first level support that the developers should look into this, but she seemed to indicate that there was a slim chance of that happening. I don't know if this information will help you or not in your efforts, but I wanted to give you an update on what I found out.

Best wishes! - Eric-

View solution in original post

0 Kudos
8 Replies
MichaelVolz
Esteemed Contributor

What version of ArcGIS are you running?

Are you executing the py script in a Windows Scheduled Task?

0 Kudos
EricAnderson14
Occasional Contributor

We are running ArcGIS version 10.5.

As far as execution is concerned, I was running the '.py' file by executing it through the dos command by calling the '.py' file.

Thanks for any insight you may be able to provide where I may have gone off track!

- Eric -

0 Kudos
JonathanQuinn
Esri Notable Contributor

Some other thoughts:

What version of Python are you running it in outside of ArcMap?  You can add:

import sys
print(sys.version)

You can run this in ArcMap to make sure the versions are the same, (assuming you're not using the version included with the installation of ArcMap).

The in_table parameter seems funny...

in_table="C:/Users/Public/Documents/Geocoding/Addresses_To_Geocode.xlsx.xls/Excel_Destination"

Should it have two extensions?

Can you run a simple buffer to see if that goes through?  Perhaps you can isolate it to the Geocode Addresses tool.

0 Kudos
EricAnderson14
Occasional Contributor

According to the Print command you suggested, we are running version 2.7.12 of Python.

The end goal will be to get this to run from Scheduler, but I wanted to try to slug my way through any problems using the DOS command first.

Thank you all for your help in finding what the problem might be.

- Eric -

0 Kudos
EricAnderson14
Occasional Contributor

I ran a Buffer process, in ArcMap, obtained the Python snippet in the same way, posted it to my python script and ran that. The results of the Buffer using Python under the DOS prompt worked just fine.

I changed the name of my Excel spreadsheet to remove the extra '.xlsx' from it and then also change the file name in the python script. The end result of that test was a failure of the same type that I had initially. It sounds like the issue has to do with Geocoding at this point.

Any additional insight would be greatly appreciated.

Thank you! - Eric-

0 Kudos
ArjunDongre
Regular Contributor

Any solution to this problem? I have been having a problem with the geocoding tool not accepting the path for the locator when run in a scheduled task. The locator sits in a folder on a mapped network drive, the rest of the data is on the local C drive. So my setup is similar to yours. The script runs as expected when running from cmd or within IDLE, but not as a scheduled task. Any thoughts on how to move forward would be appreciated.

0 Kudos
EricAnderson14
Occasional Contributor

Hi there Arjun,

Unfortunately, first level support wasn't able to fix my problem, but through their help, they un-intentionally pointed me in the right direction for an alternative. I was trying to process a large (30,000 row) excel spreadsheet. It worked fine in ArcMap, as well as ArcPy being run from ArcMap. However, when I tried to run it through the command prompt, it failed. What I eventually figured out was that if I converted my Excel spreadsheet to a CSV file, the python script would run fine from the command line.

I tried to express to first level support that the developers should look into this, but she seemed to indicate that there was a slim chance of that happening. I don't know if this information will help you or not in your efforts, but I wanted to give you an update on what I found out.

Best wishes! - Eric-

0 Kudos
ArjunDongre
Regular Contributor

So for whatever reason, the geocoding function did not like my mapped path to the locator (like c:\path\to\locator). I ended up using the server name itself (r\\servername\path\to\folder) and that did the trick. Not sure why the geocoding tool is so finicky.

0 Kudos