<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SearchCursor throws error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568987#M44581</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, I have edited your script to work in Pythonwin in Desktop to debug the script. I see that you are using ArcServer attributes, which is not a useful place to debug a script. I suspected that you had not installed python on the server, but if you get it to start, then that cannot be the case.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# testbug.py
import arcinfo
import arcpy
import sys

def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; global mosaicDb
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; global pathtable
&amp;nbsp;&amp;nbsp;&amp;nbsp; # only a geoprocessing service can do this:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # pathtable = '%SCRATCHWORKSPACE%/Scratch.gdb/Paths'
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Desktop equivalent 9.3+
&amp;nbsp;&amp;nbsp;&amp;nbsp; installTemp = arcpy.GetSystemEnvironment("ARCTEMPDIR")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.scratchWorkspace = installTemp+"/scratch.gdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not arcpy.Exists(arcpy.env.scratchWorkspace):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "failed to set scratch workspace"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sys.exit()
&amp;nbsp;&amp;nbsp;&amp;nbsp; pathtable = arcpy.env.scratchWorkspace +"/Paths"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print pathtable
&amp;nbsp;&amp;nbsp;&amp;nbsp; mosaicDb = r'D:\data\aerial\catalog\nzmgcat.gdb' # '//sdm7/arcgis/Mosaics/imagery_datasets.gdb/'

&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; inputmosaic = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; objectid = arcpy.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; inputmosaic = 'nztm1'
&amp;nbsp;&amp;nbsp;&amp;nbsp; objectid = '40'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Input Mosaic Dataset: ' + mosaicDb + "/" + inputmosaic) # bug fix added separator
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Search SourceObjectID: ' + objectid)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Input Mosaic Dataset: ' + mosaicDb + "/" + inputmosaic
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Search SourceObjectID: ' + objectid
&amp;nbsp;&amp;nbsp;&amp;nbsp; deletePathDb(pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; exportCatalog(inputmosaic,pathtable,mosaicDb)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fs = getMosaicRow(objectid, pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print fs
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameter(3, fs) # Not 0, this would have to be at least the third parameter

def deletePathDb(pathtable):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(pathtable):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('table deleted successfully')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'pathtable deleted successfully'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'pathtable does not exist'
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #catch because will throw error if table not there
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "error in deletePathDb"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Error attempting delete path table')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages())

def exportCatalog(name,pathtable,mosaicDb):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullname = mosaicDb + '/' + name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ExportRasterCatalogPaths_management(fullname, "ALL", pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Error export catalog")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages())

def getMosaicRow(objectId, table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; where = 'SourceOID = ' + objectId # this is my objectid field name
&amp;nbsp;&amp;nbsp;&amp;nbsp; #this was line that explodes
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.SearchCursor(table, where)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fs = None
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # fs = row # this will be a geoprocessing row object of no value outside the cursor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sPath = row.path
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nSourceOID = row.SourceOID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nOID = row.OID
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor 
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (nOID,nSourceOID,sPath)# return a tuple which contains the field contents

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()
&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;c:\workspace/scratch.gdb/Paths
Input Mosaic Dataset: D:\data\aerial\catalog\nzmgcat.gdb/nztm1
Search SourceObjectID: 40
pathtable deleted successfully
(40, 40, u'D:\\data\\aerial\\catalog\\test\\r12a.jpg')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I cannot reproduce your error in Desktop.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 00:30:02 GMT</pubDate>
    <dc:creator>KimOllivier</dc:creator>
    <dc:date>2021-12-12T00:30:02Z</dc:date>
    <item>
      <title>SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568980#M44574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to create a SearchCursor on a table which seems simple enough&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.SearchCursor(tablepath)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This line of code though throws an error in _base.py:&amp;nbsp; global name 'gp_' in not defined.&amp;nbsp; I cannot seem to find any information on this error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can create an UpdateCursor and an InsertCursor without error using the same tablepath variable.&amp;nbsp; Is there something I am missing in this method call?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using ArcGIS 10.0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Joe&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 Jul 2012 09:20:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568980#M44574</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2012-07-01T09:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568981#M44575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Anyone have any ideas about this?&amp;nbsp; I basically cannot use a SearchCursor in any script, the same error occurs (as expected) in the Python window.&amp;nbsp; Why would this only occur on a SearchCursor when everything else is working without issue.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2012 04:31:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568981#M44575</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2012-07-03T04:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568982#M44576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;does your "tablepath" point to a path or a featureclass/shapefile?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;posting the rest of your code might help as well.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2012 05:22:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568982#M44576</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2012-07-03T05:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568983#M44577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Did you edit any of the arcpy source files? ARe you sure you're using the right version of Python? You may need to reinstall.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2012 06:50:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568983#M44577</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-07-03T06:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568984#M44578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Apologizes for not posting a more complete code sample initially&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcinfo
import arcpy
import sys






def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; global mosaicDb
&amp;nbsp;&amp;nbsp;&amp;nbsp; global pathtable
&amp;nbsp;&amp;nbsp;&amp;nbsp; pathtable = '%SCRATCHWORKSPACE%/Scratch.gdb/Paths'
&amp;nbsp;&amp;nbsp;&amp;nbsp; mosaicDb = '//sdm7/arcgis/Mosaics/imagery_datasets.gdb/'


&amp;nbsp;&amp;nbsp;&amp;nbsp; inputmosaic = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; objectid = arcpy.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Input Mosaic Dataset: ' + mosaicDb + inputmosaic)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Search SourceObjectID: ' + objectid)


&amp;nbsp;&amp;nbsp;&amp;nbsp; deletePathDb()
&amp;nbsp;&amp;nbsp;&amp;nbsp; exportCatalog(inputmosaic)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fs = getMosaicRow(objectid, pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameter(0, fs)




def deletePathDb():
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('table deleted successfully')
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #catch because will throw error if table not there
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Error attempting delete path table')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages())






def exportCatalog(name):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullname = '//sdm7/arcgis/Mosaics/imagery_datasets.gdb/' + name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ExportRasterCatalogPaths_management(fullname, "ALL", pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Error export catalog")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages())




def getMosaicRow(objectId, table):


&amp;nbsp;&amp;nbsp;&amp;nbsp; where = 'SourceOID = ' + objectId
#this is line that explodes
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.SearchCursor(table, where)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; fs = None
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fs = row
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; return fs
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As I mentioned above, if I replace SearchCursor with UpdateCursor or InsertCursor it works without error, which is the thing that has my head spinning the most.&amp;nbsp; I have certainly not consciously modified any of the core .&amp;nbsp; I am using 10.0 with Python26&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for you help&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:29:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568984#M44578</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2021-12-12T00:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568985#M44579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am suspicious of your query to open the cursor. Is ObjectID a string? If not it needs to be cast to a string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What happens if the result is no records?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Add some print statements to print out what is returned.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have never used the row variable in a cursor, always row.attribute, what does row return?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Update and Insert cursors work differently and since you haven't added a new row it probably just does nothing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You also need to close the cursor but I suppose that you are relying on the local variables in the function. I would still explicitly 'del cursor'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You may have more success by rearranging your whole script. I would avoid opening and reopening a cursor just to get one record.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe get all the values in one pass and put into a python dictionary? That would be much faster.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jul 2012 20:24:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568985#M44579</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2012-07-03T20:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568986#M44580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I am suspicious of your query to open the cursor. Is ObjectID a string? If not it needs to be cast to a string.&lt;BR /&gt;What happens if the result is no records?&lt;BR /&gt;Add some print statements to print out what is returned.&lt;BR /&gt;I have never used the row variable in a cursor, always row.attribute, what does row return?&lt;BR /&gt;&lt;BR /&gt;Update and Insert cursors work differently and since you haven't added a new row it probably just does nothing.&lt;BR /&gt;You also need to close the cursor but I suppose that you are relying on the local variables in the function. I would still explicitly 'del cursor'&lt;BR /&gt;&lt;BR /&gt;You may have more success by rearranging your whole script. I would avoid opening and reopening a cursor just to get one record.&lt;BR /&gt;Maybe get all the values in one pass and put into a python dictionary? That would be much faster.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kimo,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the reply, perhaps my initial post was not clear this line throws the error (&lt;P align="left"&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #444444; font-family: Verdana;"&gt;global name 'gp_' in not defined)&lt;/SPAN&gt;&lt;SPAN&gt;&lt;P&gt;&lt;/P&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

cursor = arcpy.SearchCursor(table, where)

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It throws the error if the where clause is not in there and if I just pass the table in (but yes objectId is a string).&amp;nbsp; The table is created in the &lt;P align="left"&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #444444; font-family: Courier New;"&gt;exportCatalog &lt;/SPAN&gt;&lt;SPAN&gt;&lt;P&gt;&lt;/P&gt;method so perhaps it has something to do with trying to query a table that was just created. I cannot put in statements to see what is returned because it blows up on that call&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The purpose of the script is to retrieve only the one value (at this point), so it is not running multiple times to retrieve multiple values.&amp;nbsp; I am quite inexperienced with python and geoprocessing so I am sure I am not doing this in the most efficient manner but right now I am just trying to get what seems a pretty straightforward script to work as a geopocessing task&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Joe&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:29:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568986#M44580</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2021-12-12T00:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568987#M44581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, I have edited your script to work in Pythonwin in Desktop to debug the script. I see that you are using ArcServer attributes, which is not a useful place to debug a script. I suspected that you had not installed python on the server, but if you get it to start, then that cannot be the case.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# testbug.py
import arcinfo
import arcpy
import sys

def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; global mosaicDb
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; global pathtable
&amp;nbsp;&amp;nbsp;&amp;nbsp; # only a geoprocessing service can do this:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # pathtable = '%SCRATCHWORKSPACE%/Scratch.gdb/Paths'
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Desktop equivalent 9.3+
&amp;nbsp;&amp;nbsp;&amp;nbsp; installTemp = arcpy.GetSystemEnvironment("ARCTEMPDIR")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.scratchWorkspace = installTemp+"/scratch.gdb"
&amp;nbsp;&amp;nbsp;&amp;nbsp; if not arcpy.Exists(arcpy.env.scratchWorkspace):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "failed to set scratch workspace"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sys.exit()
&amp;nbsp;&amp;nbsp;&amp;nbsp; pathtable = arcpy.env.scratchWorkspace +"/Paths"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print pathtable
&amp;nbsp;&amp;nbsp;&amp;nbsp; mosaicDb = r'D:\data\aerial\catalog\nzmgcat.gdb' # '//sdm7/arcgis/Mosaics/imagery_datasets.gdb/'

&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; inputmosaic = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; objectid = arcpy.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; inputmosaic = 'nztm1'
&amp;nbsp;&amp;nbsp;&amp;nbsp; objectid = '40'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Input Mosaic Dataset: ' + mosaicDb + "/" + inputmosaic) # bug fix added separator
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Search SourceObjectID: ' + objectid)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Input Mosaic Dataset: ' + mosaicDb + "/" + inputmosaic
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Search SourceObjectID: ' + objectid
&amp;nbsp;&amp;nbsp;&amp;nbsp; deletePathDb(pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; exportCatalog(inputmosaic,pathtable,mosaicDb)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fs = getMosaicRow(objectid, pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print fs
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameter(3, fs) # Not 0, this would have to be at least the third parameter

def deletePathDb(pathtable):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(pathtable):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('table deleted successfully')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'pathtable deleted successfully'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else :
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'pathtable does not exist'
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #catch because will throw error if table not there
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "error in deletePathDb"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage('Error attempting delete path table')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages())

def exportCatalog(name,pathtable,mosaicDb):
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullname = mosaicDb + '/' + name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.ExportRasterCatalogPaths_management(fullname, "ALL", pathtable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception as e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Error export catalog")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages())

def getMosaicRow(objectId, table):
&amp;nbsp;&amp;nbsp;&amp;nbsp; where = 'SourceOID = ' + objectId # this is my objectid field name
&amp;nbsp;&amp;nbsp;&amp;nbsp; #this was line that explodes
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.SearchCursor(table, where)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fs = None
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # fs = row # this will be a geoprocessing row object of no value outside the cursor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sPath = row.path
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nSourceOID = row.SourceOID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nOID = row.OID
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor 
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (nOID,nSourceOID,sPath)# return a tuple which contains the field contents

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()
&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;c:\workspace/scratch.gdb/Paths
Input Mosaic Dataset: D:\data\aerial\catalog\nzmgcat.gdb/nztm1
Search SourceObjectID: 40
pathtable deleted successfully
(40, 40, u'D:\\data\\aerial\\catalog\\test\\r12a.jpg')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I cannot reproduce your error in Desktop.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:30:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568987#M44581</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-12T00:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568988#M44582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Kim,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate the time you took setting t on my his up.&amp;nbsp; I kind of jump between trying to run on the server and working desktop.&amp;nbsp; I think I may try to reinstall python on my desktop and see what that does.&amp;nbsp; I basically cannot seem to create a SearchCursor in any way, even just in the py window with an existing table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a related question.&amp;nbsp; I think there is something I am just not grasping here.&amp;nbsp; I do have the script successfully creating the path output table as a geoprocessing service.&amp;nbsp; I did finally realize that my output variable should be index 3, as you note in your comments (was thinking output started at 0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I have the table in my scratch workspace and I want to to just send that table back to the caller of the service as a result how does one go about doing that.&amp;nbsp; I have tried different ways of defining the output parameter and calling both SetParameter or SetParamaterAsText.&amp;nbsp; Always get that "Object error in setting parameter....'.&amp;nbsp; I know there is something really fundamental I am just not getting my head around, could you possibly point me in the right direction?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Joe&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jul 2012 10:36:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568988#M44582</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2012-07-04T10:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568989#M44583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry, can't help with server. I might now try installing ArcServer 10.1 since it is easier to manage.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2012 10:33:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568989#M44583</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2012-07-05T10:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: SearchCursor throws error</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568990#M44584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So I re-installed ArcGIS and Python and the SearchCursor works now, so was a problem with the install.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for all the help&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Joe&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Jul 2012 10:01:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-throws-error/m-p/568990#M44584</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2012-07-08T10:01:57Z</dc:date>
    </item>
  </channel>
</rss>

