0

I'm attempting to run an arcpy script from PHP, but it fails every time, giving me no error messages. The only message displayed is:

Failed at Fri Apr 21 13:25:50 2017 (Elapsed Time: 0.00 seconds)

The script works perfectly when I directly execute the .py file in my desktop, or when I run it from ArcMap (v10.2.2) after importing it.

I've tried running some other (much simpler) arcpy scripts from PHP with no issues... is just this one that is causing trouble.

Here's the code:

import arcpy

arcpy.CheckOutExtension("Network")

Network_Dataset = "C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Routing_ND.nd"
TRP = "TRP"
emplist = "Database Connections\\OLE DB Connection.odc\\.emplist"
UsersCoord = "_Layer"
UsersShape = "C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\User_Locations.shp"
Depot = "C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Depot.shp"
Routes_dbf = "C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Routes.dbf"
Orders_dbf = "C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders_1.dbf"
v_request_day = "Database Connections\\OLE DB Connection.odc\\.reqday"
Exp_Orders = "C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders.shp"
Intermediate = "C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate"

try:
    arcpy.MakeVehicleRoutingProblemLayer_na(Network_Dataset, "TRP", "Minutes", "Miles", "Minutes", "Miles", "", "1", "Low", "High", "ALLOW_DEAD_ENDS_ONLY", "Oneway;'Avoid Limited Access Roads';'Avoid Unpaved Roads';'Avoid Toll Roads';Walkway;RDMs", "USE_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES")
    arcpy.UpdateAnalysisLayerAttributeParameter_na(TRP, "Walkway", "Restriction Usage", "AVOID_HIGH")
    arcpy.UpdateAnalysisLayerAttributeParameter_na(TRP, "Avoid Limited Access Roads", "Restriction Usage", "AVOID_HIGH")
    arcpy.UpdateAnalysisLayerAttributeParameter_na(TRP, "Avoid Toll Roads", "Restriction Usage", "AVOID_HIGH")
    arcpy.UpdateAnalysisLayerAttributeParameter_na(TRP, "Avoid Unpaved Roads", "Restriction Usage", "AVOID_LOW")
    arcpy.UpdateAnalysisLayerAttributeParameter_na(TRP, "Oneway", "Restriction Usage", "PROHIBITED")
    arcpy.UpdateAnalysisLayerAttributeParameter_na(TRP, "RDMs", "Restriction Usage", "PROHIBITED")
    arcpy.MakeXYEventLayer_management(emplist, "longitude", "latitude", UsersCoord, "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;0.001;0.001;IsHighPrecision", "")
    arcpy.FeatureClassToFeatureClass_conversion(UsersCoord, Intermediate, "User_Locations.shp", "", "name \"name\" true true false 4 Long 0 10 ,First,#,_Layer,name,-1,-1;employee_n \"employee_n\" true true false 91 Text 0 0 ,First,#,_Layer,emp_name,-1,-1;emp_a \"emp_a\" true true false 229 Text 0 0 ,First,#,_Layer,emp_address,-1,-1;longitude \"longitude\" true true false 8 Double 0 0 ,First,#,_Layer,longitude,-1,-1;latitude \"latitude\" true true false 8 Double 0 0 ,First,#,_Layer,latitude,-1,-1", "")
    arcpy.AddLocations_na(TRP, "Orders", UsersShape, "Name name #;DeliveryQuantities # 1;MaxViolationTime2 # #", "5000 Meters", "", "Streets SHAPE;TSM_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Streets #;TSM_ND_Junctions #")
    arcpy.AddLocations_na(TRP, "Depots", Depot, "Name Name #;Description # #", "5000 Meters", "", "Streets SHAPE;TSM_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Streets #;TSM_ND_Junctions #")
    arcpy.AddLocations_na(TRP, "Routes", Routes_dbf, "Name Name #;StartDepotName StartDepot #;Capacities # 4;FixedCost # 6;EarliestStartTime # '01:00:00 AM';LatestStartTime # '01:00:00 AM';ArriveDepartDelay # 1;CostPerUnitTime # 1;CostPerUnitDistance # 3.22;OvertimeStartTime # 35;CostPerUnitOvertime # 1;MaxTotalTime # 35", "5000 Meters", "", "Streets SHAPE;TSM_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "Streets #;TSM_ND_Junctions #")
    arcpy.Solve_na(TRP, "HALT", "TERMINATE", "")
    arcpy.SelectData_management(TRP, "Orders")
    arcpy.FeatureClassToFeatureClass_conversion("Orders", Intermediate, "Orders.shp", "", "Name \"Name\" true true true 128 Text 0 0 ,First,#,TRP\\Orders,Name,-1,-1;RouteName \"RouteName\" true true true 128 Text 0 0 ,First,#,TRP\\Orders,RouteName,-1,-1;Sequence \"Sequence\" true true true 4 Long 0 0 ,First,#,TRP\\Orders,Sequence,-1,-1;FromPrevTr \"FromPrevTr\" true true true 8 Double 0 0 ,First,#,TRP\\Orders,FromPrevTravelTime,-1,-1;FromPrevDi \"FromPrevDi\" true true true 8 Double 0 0 ,First,#,TRP\\Orders,FromPrevDistance,-1,-1;CumulTrave \"CumulTrave\" true true true 8 Double 0 0 ,First,#,TRP\\Orders,CumulTravelTime,-1,-1;CumulDista \"CumulDista\" true true true 8 Double 0 0 ,First,#,TRP\\Orders,CumulDistance,-1,-1;CumulTime \"CumulTime\" true true true 8 Double 0 0 ,First,#,TRP\\Orders,CumulTime,-1,-1", "")
    arcpy.AddField_management(Exp_Orders, "date_used", "TEXT", "", "", "25", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.CalculateField_management(Exp_Orders, "date_used", "datetime.datetime.now( )", "PYTHON", "")
    arcpy.TableToDBASE_conversion("C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders.shp", Intermediate)
    arcpy.Append_management("C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders_1.dbf", v_request_day, "NO_TEST", "id_petition \"id_petition\" true true false 4 Long 0 10 ,First,#;sequence \"sequence\" true true false 4 Long 0 10 ,First,#,C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders_1.dbf,Sequence,-1,-1;date_used \"date_used\" true true false 16 Date 0 0 ,First,#,C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders_1.dbf,date_used,-1,-1;id_emp \"id_emp\" true false false 4 Long 0 10 ,First,#,C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders_1.dbf,Name,-1,-1;route_name \"route_name\" true false false 50 Text 0 0 ,First,#,C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders_1.dbf,RouteName,-1,-1;route_distance \"route_distance\" true false false 8 Double 0 0 ,First,#,C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders_1.dbf,CumulDista,-1,-1;route_time \"route_time\" true false false 8 Double 0 0 ,First,#,C:\\Users\\username\\Documents\\ArcGIS\\Geoprocessing\\Intermediate\\Orders_1.dbf,CumulTime,-1,-1", "")
    arcpy.CheckInExtension("Network")

except:
    print(arcpy.GetMessages())

I also tried printing an "Step -name of the step- Ok" message after each line to try to find the specific step where the script is failing, and the message I get is

"Step: Update Analysis Layer Attribute Parameter - OK"

meaning that the step where it's failing is the next one: "Make XY Event Layer".

Is there any way I can make it throw a more detailed error?

  • 4
    Remove your try/except statements so that you can see the error messages that Python provides. – PolyGeo Apr 21 '17 at 19:27
  • @PolyGeo I tried that too, I get no messages. – AntonioH Apr 21 '17 at 19:40
  • 1
    I think you should remove it from the code snippet for testing and presenting here anyway. I find that aiming for an MCVE is usually the quickest way to a solution. – PolyGeo Apr 21 '17 at 19:44
  • What type of database is emplist referencing? – Midavalo Apr 21 '17 at 19:57
  • @Midavalo emplist is a table in a MySQL database. It contains only Names and Lat/Lon data... Then after the routes calculation, the outputs are appended to the v_request_day table in the same database. – AntonioH Apr 21 '17 at 20:08

Your Answer

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

Browse other questions tagged or ask your own question.