import os import arcpy from datetime import datetime ###################################### ###### Getting params ###### ###################################### input_json=arcpy.GetParameterAsText(0) ###################################### ###### Store Data ###### ###################################### dt="DATA_EXTRACT_"+datetime.today().strftime("%y%m%d_%H%M%S") json_file=os.path.join(arcpy.env.scratchFolder,"%s.json"%dt) fc=os.path.join(arcpy.env.scratchGDB,dt) ###CONVERT JSON TO FC### arcpy.AddMessage("Converting JSON to FC...") f=open(json_file,'w') f.write(input_json) f.close() res=arcpy.JSONToFeatures_conversion(json_file,fc) ###Storing result...### arcpy.SetParameter(1,arcpy.FeatureSet(fc))
{"features": [{"geometry": {"y": 35.748388281000075, "x": -114.85761096699997}, "attributes": {"SITENAME": "MYSITE", "OBJECTID": 1}}], "fieldAliases": {"SITENAME": "SITENAME", "OBJECTID": "OBJECTID"}, "fields": [{"alias": "OBJECTID", "type": "esriFieldTypeOID", "name": "OBJECTID"}, {"alias": "SITENAME", "length": 70, "type": "esriFieldTypeString", "name": "SITENAME"}], "displayFieldName": "SITENAME", "spatialReference": {"wkid": 4269, "latestWkid": 4269}, "geometryType": "esriGeometryPoint"}
Executing: JsonToFc "{"features": [{"geometry": {"y": 35.748388281000075, "x": -114.85761096699997}, "attributes": {"SITENAME": "MYSITE", "OBJECTID": 1}}], "fieldAliases": {"SITENAME": "SITENAME", "OBJECTID": "OBJECTID"}, "fields": [{"alias": "OBJECTID", "type": "esriFieldTypeOID", "name": "OBJECTID"}, {"alias": "SITENAME", "length": 70, "type": "esriFieldTypeString", "name": "SITENAME"}], "displayFieldName": "SITENAME", "spatialReference": {"wkid": 4269, "latestWkid": 4269}, "geometryType": "esriGeometryPoint"}" Start Time: Mon Aug 05 09:51:35 2013 Running script JsonToFc... Converting JSON to FC... Completed script JsonToFc... Succeeded at Mon Aug 05 09:51:44 2013 (Elapsed Time: 9.49 seconds)
{ "error": { "code": 400, "message": "Unable to complete operation.", "details": [ "Error executing tool." ] } }
Level Time Message Source Machine Code Time Elapsed User Name Process Thread Method Name
SEVERE Aug 5, 2013, 9:53:11 AM Error executing tool. ExtractDataTools/JsonToFc.GPServer <HOSTNAME>.<DOMAINNAME> 20010 anonymous 5212 7528 GPServerSync.CheckMessages
SEVERE Aug 5, 2013, 9:53:11 AM Traceback (most recent call last): File "\\<FILESERVER>\<SHARE>$\directories\arcgissystem\arcgisinput\ExtractDataTools\JsonToFc.GPServer\extracted\v101\zipandship\JsonToFc.py", line 44, in res=arcpy.JSONToFeatures_conversion(json_file,fc) File "c:\program files\arcgis\server\arcpy\arcpy\conversion.py", line 430, in JSONToFeatures raise e ExecuteError: ERROR 000206: Cannot create FeatureClass 'C:\Users\<AGS SERVICE ACCOUNT>\AppData\Local\Temp\extractdatatools\jsontofc_gpserver\j631f8a7a49c34355a03361601e636c75\scratch\scratch.gdb\DATA_EXTRACT_130805_095310'. Failed to execute (JSONToFeatures). Failed to execute (JsonToFc). Failed to execute (JSON To Feature Class).
Solved! Go to Solution.
import os import arcpy from datetime import datetime ###################################### ###### Getting params ###### ###################################### input_json=arcpy.GetParameterAsText(0) ###################################### ###### Prepare workspaces ###### ###################################### dt="DATA_EXTRACT_"+datetime.today().strftime("%y%m%d_%H%M%S") ws=arcpy.env.scratchFolder json_file=os.path.join(ws,"%s.json"%dt) res=arcpy.CreateFileGDB_management(ws,dt) fgdb=res.getOutput(0) fc=os.path.join(fgdb,dt) ###################################### ###### Store JSON to file ###### ###################################### arcpy.AddMessage("Converting JSON to FC...") f=open(json_file,'w') f.write(input_json) f.close() #DOES NOT WORK FROM 64-bit... try: res=arcpy.JSONToFeatures_conversion(json_file,fc) except: arcpy.AddWarning("Could not run JSONToFeature_conversion nativly... Attempting to run in 32-bit mode...") ############################################## ###### Subprocess call to 32-bit ###### ############################################## #setup call and execute... import subprocess python=r'C:/Python27/ArcGIS10.2/python.exe' cmd="""%s -c " import sys sys.path=[] sys.path.append(r'C:\Windows\system32\python27.zip') sys.path.append(r'C:\Python27\ArcGIS10.2\DLLs') sys.path.append(r'C:\Python27\ArcGIS10.2\lib') sys.path.append(r'C:\Python27\ArcGIS10.2\lib\plat-win') sys.path.append(r'C:\Python27\ArcGIS10.2\lib\lib-tk') sys.path.append(r'C:\Python27\ArcGIS10.2') sys.path.append(r'C:\Python27\ArcGIS10.2\lib\site-packages') sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\\bin') sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\\arcpy') sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Scripts') import arcpy; res=arcpy.JSONToFeatures_conversion(%s,%s) print res.status print res.getMessages() " """%(python,"'"+json_file.replace("\\","/")+"'","'"+fc.replace("\\","/")+"'") arcpy.AddMessage("SUBPROCESS COMMAND: \n%s"%cmd) out="" try: p = subprocess.Popen(cmd, stdout=subprocess.PIPE) out, err = p.communicate() if (err!=None): arcpy.AddError("Execution failed for some reason...\n%s"%out) sys.exit() except: arcpy.AddError("Exception thrown... Not caught... ") sys.exit() #get output and check status sout=out.split("\r\n") if len(sout) >1: res_status=sout[0] res_messages="\n".join(sout[1:]) if res_status != '4': arcpy.AddError("JSONToFeatures_conversion failed...\n%s"%out) arcpy.AddError("CMD: %s"%cmd) else: arcpy.AddMessage("JSONToFeatures_converson succeeded! \n%s"%res_messages) else: sys.exit()
Messages
Executing: JsonToFcSubprocess "{"features": [{"geometry": {"y": 35.748388281000075, "x": -114.85761096699997}, "attributes": {"SITENAME": "MYSITE", "OBJECTID": 1}}], "fieldAliases": {"SITENAME": "SITENAME", "OBJECTID": "OBJECTID"}, "fields": [{"alias": "OBJECTID", "type": "esriFieldTypeOID", "name": "OBJECTID"}, {"alias": "SITENAME", "length": 70, "type": "esriFieldTypeString", "name": "SITENAME"}], "displayFieldName": "SITENAME", "spatialReference": {"wkid": 4269, "latestWkid": 4269}, "geometryType": "esriGeometryPoint"}"
Start Time: Tue Aug 06 14:13:57 2013
Running script JsonToFcSubprocess...
Converting JSON to FC...
Completed script JsonToFcSubprocess...
Succeeded at Tue Aug 06 14:14:01 2013 (Elapsed Time: 4.46 seconds)
{
"results": [
],
"messages": [
{
"type": "esriJobMessageTypeInformative",
"description": "Executing (JSON To Feature Class subprocess): JsonToFcSubprocess {\"features\":[{\"geometry\":{\"y\":35.748388281000075,\"x\":-114.85761096699997},\"attributes\":{\"SITENAME\":\"MYSITE\",\"OBJECTID\":1}}],\"fieldAliases\":{\"SITENAME\":\"SITENAME\",\"OBJECTID\":\"OBJECTID\"},\"fields\":[{\"alias\":\"OBJECTID\",\"type\":\"esriFieldTypeOID\",\"name\":\"OBJECTID\"},{\"alias\":\"SITENAME\",\"length\":70,\"type\":\"esriFieldTypeString\",\"name\":\"SITENAME\"}],\"displayFieldName\":\"SITENAME\",\"spatialReference\":{\"wkid\":4269,\"latestWkid\":4269},\"geometryType\":\"esriGeometryPoint\"}"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Start Time: Tue Aug 06 14:18:53 2013"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Executing (JsonToFcSubprocess): JsonToFcSubprocess {\"features\":[{\"geometry\":{\"y\":35.748388281000075,\"x\":-114.85761096699997},\"attributes\":{\"SITENAME\":\"MYSITE\",\"OBJECTID\":1}}],\"fieldAliases\":{\"SITENAME\":\"SITENAME\",\"OBJECTID\":\"OBJECTID\"},\"fields\":[{\"alias\":\"OBJECTID\",\"type\":\"esriFieldTypeOID\",\"name\":\"OBJECTID\"},{\"alias\":\"SITENAME\",\"length\":70,\"type\":\"esriFieldTypeString\",\"name\":\"SITENAME\"}],\"displayFieldName\":\"SITENAME\",\"spatialReference\":{\"wkid\":4269,\"latestWkid\":4269},\"geometryType\":\"esriGeometryPoint\"}"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Start Time: Tue Aug 06 14:18:53 2013"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Running script JsonToFcSubprocess..."
},
{
"type": "esriJobMessageTypeInformative",
"description": "Converting JSON to FC..."
},
{
"type": "esriJobMessageTypeWarning",
"description": "Could not run JSONToFeature_conversion nativly... Attempting to run in 32-bit mode..."
},
{
"type": "esriJobMessageTypeInformative",
"description": "SUBPROCESS COMMAND: \n\\\\<SERVER>\\<SHARE>$\\directories\\arcgissystem\\arcgisinput\\ExtractDataTools\\JsonToFcSubprocess.GPServer\\extracted\\v101\\..\\cd\\arcgis10_2\\python.exe -c \"\n import sys\n sys.path=[]\n sys.path.append(r'C:\\Windows\\system32\\python27.zip')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\DLLs')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\lib')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\lib\\plat-win')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\lib\\lib-tk')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\lib\\site-packages')\n sys.path.append(r'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\bin')\n sys.path.append(r'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\arcpy')\n sys.path.append(r'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\ArcToolbox\\Scripts')\n import arcpy;\n res=arcpy.JSONToFeatures_conversion('C:/Users/<SERVICE ACCOUNT>/AppData/Local/Temp/extractdatatools/jsontofcsubprocess_gpserver/j68e8efd3ab8c4a4aaec0045ab6debe1a/scratch/DATA_EXTRACT_130806_141853.json','C:/Users/<SERVICE ACCOUNT>/AppData/Local/Temp/extractdatatools/jsontofcsubprocess_gpserver/j68e8efd3ab8c4a4aaec0045ab6debe1a/scratch/DATA_EXTRACT_130806_141853.gdb/DATA_EXTRACT_130806_141853')\n print res.status\n print res.getMessages()\n \"\n "
},
{
"type": "esriJobMessageTypeInformative",
"description": "Completed script JsonToFcSubprocess..."
},
{
"type": "esriJobMessageTypeInformative",
"description": "Succeeded at Tue Aug 06 14:18:55 2013 (Elapsed Time: 1.84 seconds)"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Succeeded at Tue Aug 06 14:18:55 2013 (Elapsed Time: 1.84 seconds)"
}
]
}
Cannot create FeatureClass 'C:\Users\<AGS SERVICE ACCOUNT>\AppData\Local\Temp\extractdatatools\jsontofc_gpserver\j631f8a7a49c34355a03361601e636c75\scratch\scratch.gdb\DATA_EXTRACT_130805_095310'
Cannot create FeatureClass 'C:\Users\<AGS SERVICE ACCOUNT>\AppData\Local\Temp\extractdatatools\jsontofc_gpserver\j631f8a7a49c34355a03361601e636c75\scratch\scratch.gdb\DATA_EXTRACT_130805_095310'
Just a complete shot in the dark here and I have absolutely zero experience with this method, but... Have you attempted to write the FC to in_memory instead of the Scratch.gdb? Really not sure if this is going to anything at all for you, but maybe worth a try.
import os import arcpy from datetime import datetime ###################################### ###### Getting params ###### ###################################### input_json=arcpy.GetParameterAsText(0) ###################################### ###### Store Data ###### ###################################### dt="DATA_EXTRACT_"+datetime.today().strftime("%y%m%d_%H%M%S") json_file=os.path.join(arcpy.env.scratchFolder,"%s.json"%dt) #fc=os.path.join(arcpy.env.scratchGDB,dt) fc="in_memory\%s"%dt ###CONVERT JSON TO FC### arcpy.AddMessage("Converting JSON to FC...") f=open(json_file,'w') f.write(input_json) f.close() res=arcpy.JSONToFeatures_conversion(json_file,fc) ###Storing result...### arcpy.SetParameter(1,arcpy.FeatureSet(fc)) ###cleanup...### #arcpy.Delete_management(fc) #arcpy.Delete_management(json_file)
Traceback (most recent call last): File "\\<HOST>\<SHARE>$\directories\arcgissystem\arcgisinput\ExtractDataTools\JsonToFc.GPServer\extracted\v101\zipandship\JsonToFc.py", line 45, in res=arcpy.JSONToFeatures_conversion(json_file,fc) File "c:\program files\arcgis\server\arcpy\arcpy\conversion.py", line 430, in JSONToFeatures raise e ExecuteError: ERROR 000206: Cannot create FeatureClass 'in_memory\DATA_EXTRACT_130806_075502'. Failed to execute (JSONToFeatures). Failed to execute (JsonToFc). Failed to execute (JSON To Feature Class).
import os import arcpy from datetime import datetime ###################################### ###### Getting params ###### ###################################### input_json=arcpy.GetParameterAsText(0) ###################################### ###### Prepare workspaces ###### ###################################### dt="DATA_EXTRACT_"+datetime.today().strftime("%y%m%d_%H%M%S") ws=arcpy.env.scratchFolder json_file=os.path.join(ws,"%s.json"%dt) res=arcpy.CreateFileGDB_management(ws,dt) fgdb=res.getOutput(0) fc=os.path.join(fgdb,dt) ###################################### ###### Store JSON to file ###### ###################################### arcpy.AddMessage("Converting JSON to FC...") f=open(json_file,'w') f.write(input_json) f.close() #DOES NOT WORK FROM 64-bit... try: res=arcpy.JSONToFeatures_conversion(json_file,fc) except: arcpy.AddWarning("Could not run JSONToFeature_conversion nativly... Attempting to run in 32-bit mode...") ############################################## ###### Subprocess call to 32-bit ###### ############################################## #setup call and execute... import subprocess python=r'C:/Python27/ArcGIS10.2/python.exe' cmd="""%s -c " import sys sys.path=[] sys.path.append(r'C:\Windows\system32\python27.zip') sys.path.append(r'C:\Python27\ArcGIS10.2\DLLs') sys.path.append(r'C:\Python27\ArcGIS10.2\lib') sys.path.append(r'C:\Python27\ArcGIS10.2\lib\plat-win') sys.path.append(r'C:\Python27\ArcGIS10.2\lib\lib-tk') sys.path.append(r'C:\Python27\ArcGIS10.2') sys.path.append(r'C:\Python27\ArcGIS10.2\lib\site-packages') sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\\bin') sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\\arcpy') sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Scripts') import arcpy; res=arcpy.JSONToFeatures_conversion(%s,%s) print res.status print res.getMessages() " """%(python,"'"+json_file.replace("\\","/")+"'","'"+fc.replace("\\","/")+"'") arcpy.AddMessage("SUBPROCESS COMMAND: \n%s"%cmd) out="" try: p = subprocess.Popen(cmd, stdout=subprocess.PIPE) out, err = p.communicate() if (err!=None): arcpy.AddError("Execution failed for some reason...\n%s"%out) sys.exit() except: arcpy.AddError("Exception thrown... Not caught... ") sys.exit() #get output and check status sout=out.split("\r\n") if len(sout) >1: res_status=sout[0] res_messages="\n".join(sout[1:]) if res_status != '4': arcpy.AddError("JSONToFeatures_conversion failed...\n%s"%out) arcpy.AddError("CMD: %s"%cmd) else: arcpy.AddMessage("JSONToFeatures_converson succeeded! \n%s"%res_messages) else: sys.exit()
Messages
Executing: JsonToFcSubprocess "{"features": [{"geometry": {"y": 35.748388281000075, "x": -114.85761096699997}, "attributes": {"SITENAME": "MYSITE", "OBJECTID": 1}}], "fieldAliases": {"SITENAME": "SITENAME", "OBJECTID": "OBJECTID"}, "fields": [{"alias": "OBJECTID", "type": "esriFieldTypeOID", "name": "OBJECTID"}, {"alias": "SITENAME", "length": 70, "type": "esriFieldTypeString", "name": "SITENAME"}], "displayFieldName": "SITENAME", "spatialReference": {"wkid": 4269, "latestWkid": 4269}, "geometryType": "esriGeometryPoint"}"
Start Time: Tue Aug 06 14:13:57 2013
Running script JsonToFcSubprocess...
Converting JSON to FC...
Completed script JsonToFcSubprocess...
Succeeded at Tue Aug 06 14:14:01 2013 (Elapsed Time: 4.46 seconds)
{
"results": [
],
"messages": [
{
"type": "esriJobMessageTypeInformative",
"description": "Executing (JSON To Feature Class subprocess): JsonToFcSubprocess {\"features\":[{\"geometry\":{\"y\":35.748388281000075,\"x\":-114.85761096699997},\"attributes\":{\"SITENAME\":\"MYSITE\",\"OBJECTID\":1}}],\"fieldAliases\":{\"SITENAME\":\"SITENAME\",\"OBJECTID\":\"OBJECTID\"},\"fields\":[{\"alias\":\"OBJECTID\",\"type\":\"esriFieldTypeOID\",\"name\":\"OBJECTID\"},{\"alias\":\"SITENAME\",\"length\":70,\"type\":\"esriFieldTypeString\",\"name\":\"SITENAME\"}],\"displayFieldName\":\"SITENAME\",\"spatialReference\":{\"wkid\":4269,\"latestWkid\":4269},\"geometryType\":\"esriGeometryPoint\"}"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Start Time: Tue Aug 06 14:18:53 2013"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Executing (JsonToFcSubprocess): JsonToFcSubprocess {\"features\":[{\"geometry\":{\"y\":35.748388281000075,\"x\":-114.85761096699997},\"attributes\":{\"SITENAME\":\"MYSITE\",\"OBJECTID\":1}}],\"fieldAliases\":{\"SITENAME\":\"SITENAME\",\"OBJECTID\":\"OBJECTID\"},\"fields\":[{\"alias\":\"OBJECTID\",\"type\":\"esriFieldTypeOID\",\"name\":\"OBJECTID\"},{\"alias\":\"SITENAME\",\"length\":70,\"type\":\"esriFieldTypeString\",\"name\":\"SITENAME\"}],\"displayFieldName\":\"SITENAME\",\"spatialReference\":{\"wkid\":4269,\"latestWkid\":4269},\"geometryType\":\"esriGeometryPoint\"}"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Start Time: Tue Aug 06 14:18:53 2013"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Running script JsonToFcSubprocess..."
},
{
"type": "esriJobMessageTypeInformative",
"description": "Converting JSON to FC..."
},
{
"type": "esriJobMessageTypeWarning",
"description": "Could not run JSONToFeature_conversion nativly... Attempting to run in 32-bit mode..."
},
{
"type": "esriJobMessageTypeInformative",
"description": "SUBPROCESS COMMAND: \n\\\\<SERVER>\\<SHARE>$\\directories\\arcgissystem\\arcgisinput\\ExtractDataTools\\JsonToFcSubprocess.GPServer\\extracted\\v101\\..\\cd\\arcgis10_2\\python.exe -c \"\n import sys\n sys.path=[]\n sys.path.append(r'C:\\Windows\\system32\\python27.zip')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\DLLs')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\lib')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\lib\\plat-win')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\lib\\lib-tk')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2')\n sys.path.append(r'C:\\Python27\\ArcGIS10.2\\lib\\site-packages')\n sys.path.append(r'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\bin')\n sys.path.append(r'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\arcpy')\n sys.path.append(r'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\ArcToolbox\\Scripts')\n import arcpy;\n res=arcpy.JSONToFeatures_conversion('C:/Users/<SERVICE ACCOUNT>/AppData/Local/Temp/extractdatatools/jsontofcsubprocess_gpserver/j68e8efd3ab8c4a4aaec0045ab6debe1a/scratch/DATA_EXTRACT_130806_141853.json','C:/Users/<SERVICE ACCOUNT>/AppData/Local/Temp/extractdatatools/jsontofcsubprocess_gpserver/j68e8efd3ab8c4a4aaec0045ab6debe1a/scratch/DATA_EXTRACT_130806_141853.gdb/DATA_EXTRACT_130806_141853')\n print res.status\n print res.getMessages()\n \"\n "
},
{
"type": "esriJobMessageTypeInformative",
"description": "Completed script JsonToFcSubprocess..."
},
{
"type": "esriJobMessageTypeInformative",
"description": "Succeeded at Tue Aug 06 14:18:55 2013 (Elapsed Time: 1.84 seconds)"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Succeeded at Tue Aug 06 14:18:55 2013 (Elapsed Time: 1.84 seconds)"
}
]
}
YIKES.
... having to call subprocess in 32-bit from a 64bit GP service should not be a workaround! (though that was crafty)
Can you post the incident number so I can read any of the details there.
I'll try to find out whats going on with this and see if I can offer up a better solution.
From the notes above, nothing stands out as "incorrect".