Select to view content in your preferred language

Python app based on arcpy and flask returns 87934 error when trying to set arcpy.env.workspace

412
1
12-13-2023 08:33 AM
JakubWabinski
New Contributor III

Hello, I've been developing a script that processes vector and raster data based on a REST API requests.

The script was prepared in Pycharm and worked fine on a test virtual machine (1). I created a virtual environment clone so that it could be used on the target machine (2).

However, when the same app is run on a different machine (2), the script returns AttributeError: ERROR 87934 when trying to set a workspace in a hardcoded path - the very beggining of the whole code:

 

File "C:\=====\Documents\gisapp\main.py", line 55, in set_workspace
    arcpy.env.workspace = absolute_path
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 543, in set_
    self[env] = val
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 607, in __setitem__
    ret_ = setattr(self._gp, item, value)
AttributeError: ERROR 87934

 

Here is the function that return the error. It should handle the workspace definition with all the additional code for troubleshooting:

 

    def set_workspace(location):
        absolute_path = os.path.abspath(location)
        print('Attempting to set workspace:', absolute_path)
        if isdir(absolute_path):
            print('Setting workspace:', absolute_path)
            arcpy.env.workspace = absolute_path
            set_workspace.workspace = arcpy.env.workspace
            arcpy.env.overwriteOutput = True
        else:
            print('Invalid workspace:', absolute_path)

set_workspace(r'C:\test')

 

The weird part is that the very same functionality is easily achieved when trying to set the workspace on the same machine (2) and generate a gdb in the same location but outside of flask, i.e. using this code:

 

import arcpy
absolute_path = r'C:\test'
arcpy.env.workspace = absolute_path
arcpy.management.CreateFileGDB(absolute_path, 'baza')
print('success!')

 

What is even more interesting, I tried to reproduce the error on the machine I use for everyday work (3) that is different from the one the script was first prepared (1) and the machine used in production (2), and it works perfectly fine. ArcGIS Pro 3.1 is installed on each of these machines.

Do you guys have any idea what might cause this issue? 

Thanks in advance,

Jakub

 

0 Kudos
1 Reply
AlexanderDanielPratama
Esri Contributor

In my understanding of os.path.abs is the last name of the full directory/file path. In example Path = C:\Users\Admin\.app, if you are using abs then it will show the value .app

arcpy.env.workspace is setting the environment in full path address. So it can not obtain from the abs. In my experience I rarely use this workspace unless I need to get list of domain or list of subtype or list of featureclass for spesific project. It better uses the full path.

If you aim for the geoprocessing tool or gp service function in the WAB arcgis enterprise, better to use scratchFolder and scratchGDB for the output file. Maybe that's another topic.

Hopefully, it helps your curiosity.

Cheers 

0 Kudos