2

I've edited the original post to replace a snippet of code that was producing the same error I was getting on my original code. Below is the original code that was working and then stopped after someone modified the rlf file. The script could no longer open up the template even though it was closed. The next day it ran with no issue. Does anyone know if a memory lock causes this error even if the rlf file is closed?

# Import modules

import arcpy
import os

# Create program variables

# workspace
mxd = arcpy.mapping.MapDocument(r"C:\RS_Data\workspace\BATCH_Carts_SF\BATCH_Carts_SF.mxd")

try:
    # dataframe
    df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]

    # field for SearchCursor
    numField = 'Route'

    # feature layer for cursor
    lyr = arcpy.mapping.Layer(r"C:\RS_Data\Workspace\BATCH_Carts_SF\gisdb\layers.gdb\Service_Location")

    # create empty set to hold unique route values
    rtVals = set()

    # Create searchCursor
    cursor = arcpy.SearchCursor(lyr)
    for row in cursor:
        rtVals.add(row.getValue(numField))

    # create variable to get max value for output name

    scenario = int(max(rtVals)) 

    path = "S:\\Shared\\RouteSmart\\Automated BIC and Carts\\Test\\Carts\\"

    outFolder = os.path.join(path,("{0}{1}{2}".format(path, scenario, "_Truck\\")))

    outName = os.path.join(outFolder, ("{0}{1}{2}".format(outFolder, scenario,"_Truck_Carts_Report.pdf")))
    print outName

    rlf =r"N:\Common\Report Templates\CO_SF_Carts.rlf"
    arcpy.mapping.ExportReport(lyr,rlf,outName, "USE_RLF")

except arcpy.ExecuteError:
    msgs = arcpy.GetMessages(3)
    arcpy.AddError(msgs)
    print msgs

print "done"

And here's the error from a snippet of the export report only part of the code (sorry I can't get the original error now that the script is working):

Traceback (most recent call last):
  File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript
    debugger.run(codeObject, __main__.__dict__, start_stepping=0)
  File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run
    _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 654, in run
    exec cmd in globals, locals
  File "N:\Common\Script\Drivers\export_report_test.py", line 1, in <module>
    import arcpy
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\mapping.py", line 515, in ExportReport
    return report_source._arc_object.ExportReport(*gp_fixargs((report_layout_file, output_file, dataset_option, report_title, starting_page_number, page_range, report_definition_query, extent, field_map), True))
IOError: Could not open report template

This is the additional error message I get when using try and except:

PYTHON ERRORS:
Traceback info:
  File "N:\Common\Script\Drivers\CO_051_Export_Carts_Report.py", line 5, in <module>
    import arcpy

Error Info:
<type 'str'>

ArcPy ERRORS:


ArcPy ERRORS:
  • Have you installed a newer version of python over the ArcGIS instance of it? That might have caused problems with importing arcpy. Reinstalling ArcGIS might fix that. – Fezter Sep 30 '16 at 1:42
  • No. Still using 2.7 on 10.2.2 – geoJshaun Sep 30 '16 at 1:52
  • 1
    Have you seen this answer? Ensure your PYTHONPATH is set correctly. – Fezter Sep 30 '16 at 1:57
  • What happens when you run the precise code snippet that you have presented? It looks like the error is coming from a traceback on different code and you mention that you also have try/except statements somewhere. Can you verify that you have followed the suggestions on presenting code snippets and provide error messages from running the precise code that you present, please? – PolyGeo Sep 30 '16 at 2:11
  • The error report is from the snippet. The try and except version is on a very long piece of code. I thought this would make it easier to diagnose but give the word and I will replace the snippet with the very long script. – geoJshaun Sep 30 '16 at 2:39
1

I was able to reproduce the same error:

IOError: Could not open report template

using this test code:

import arcpy
lyr = arcpy.mapping.Layer(r"C:\Temp\test.gdb\TestPolys")
arcpy.mapping.ExportReport(lyr,r"C:\Temp\test.rlf",r"C:\Temp\test.pdf","USE_RLF") 

where I know that C:\Temp\test.rlf does not exist. Consequently, I think you should double-check that the pathname to your *.rlf is correct.

It seems odd that when I ran my test the full error message included the script name (C:\Temp\test.py) and expected line number (3) on which the error occurred whereas your code snippet did not. I ran my test from IDLE.

Traceback (most recent call last): File "C:\Temp\test.py", line 3, in arcpy.mapping.ExportReport(lyr,r"C:\Temp\test.rlf",r"C:\Temp\test.pdf","USE_RLF") File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\utils.py", line 182, in fn_ return fn(*args, **kw) File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\mapping.py", line 532, in ExportReport return report_source._arc_object.ExportReport(*gp_fixargs((report_layout_file, output_file, dataset_option, report_title, starting_page_number, page_range, report_definition_query, extent, field_map), True)) IOError: Could not open report template

  • I reran it and did get the script name in the error message. Came back in this morning and ran it yet another time and it worked just fine. I replaced the snippet with the full code to be consistent. I'm concerned that when someone opens an rlf file on our system it locks it until all users log off. Perhaps I need to include code that releases any locks at the beginning of the script? – geoJshaun Sep 30 '16 at 17:02
1

The problem is caused by an alias drive "N" as a reference to the server ArcMap is installed on. I'm using a virtual desktop which points to a server with ArcMap installed on it called the N, so the rlf file is stored as "N:\Common\Report Templates\CO_SF_Carts.rlf" on the citrix console, however without the alias the pathway would be "C:RS_Data\Common\Report Templates\CO_SF_Carts.rlf". This was causing the script to not be able to find the rlf file even though python is installed on the same server as ArcMap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.