How to require info or editor in arcpy

3664
9
08-19-2015 03:38 AM
GuidoStein
New Contributor III

i have a script that edits sde and requires info or an editor license.

I know that you can use

import arcinfo

or

import arceditor

but if you have two imports, one will fail. So how do you use this pattern to require one or the other?

Thanks in advance for your help.

0 Kudos
9 Replies
WesMiller
Regular Contributor III
import arcpy
import arcinfo
if arcinfo:
     print 'info license'
else:
     import arceditor
     if arceditor:
          print 'editor license'
Luke_Pinner
MVP Regular Contributor

Wes, this won't work because a license is checked out when arcpy is imported which defaults to highest available (arcinfo if one is available, arceditor if not, or arcview if all else fails).  You need to import arcview/arceditor/arcinfo before arcpy.

Like this:

import arceditor
import arcpy
print arcpy.ProductInfo()

ArcEditor

Not like this:

import arcpy
import arceditor
print arcpy.ProductInfo()

ArcInfo

WesMiller
Regular Contributor III

Luke thanks i didn't know that. Does that mean then that it should be a try except so if he doesn't get the upper level licenses it won't run?

class LicenseError(Exception):
    pass


import arcpy


try:
    if arcpy.ProductInfo() == 'ArcInfo' or arcpy.ProductInfo() == 'ArcEditor':
        pass
    else:
        # Raise a custom exception
        #
        raise LicenseError
    print 'Do your work here'




except LicenseError:
    print "ArcInfo or ArcEditor license unavailable"  
except:
    print arcpy.GetMessages(2)
0 Kudos
GuidoStein
New Contributor III

ok, here is what I wrote up as a standalone check prior to arcpy:

import arcview

if arcview:

  print 'arcview license is available'

else:

  import arceditor

  if arceditor:

  print 'arceditor license is available'

  else:

  import arcinfo

  if arcinfo:

  print 'arcinfo license is available'

  else:

  print 'no license is available'

import arcpy

0 Kudos
GuidoStein
New Contributor III

Thanks for this...

0 Kudos
XanderBakker
Esri Esteemed Contributor

Please be aware that a bug has been reported for 10.3 and in 10.3.1 this has still not been fixed. See:

import arceditor does not set proper license level

If you have an older version (like 10.1) it will work (not sure if 10.2 works).

Luke_Pinner
MVP Regular Contributor

Xander, I'm using 10.2.2 and it works. Did you find a workaround in 10.3?

DanPatterson_Retired
MVP Emeritus

Still open....

http://support.esri.com/en/bugs/nimbus/role/beta10_1/QlVHLTAwMDA4NDI0Ng==

​no posted workaround (except a single use license...which is not an option for some)

XanderBakker
Esri Esteemed Contributor

As Dan Patterson mentions it is still open en there is no fix available. No workaround unless you want to use single use or separate a license on another server. Thanks for posting that it works in 10.2.2. Apparently it was introduced in 10.3. Might enlist for the 10.4 beta that will soon be around to see if it is fixed...

0 Kudos