Error when working with network drives

312
3
Jump to solution
03-11-2021 01:34 PM
jllorens
New Contributor II

Hello,

The last line of my script produces an error in my script when a network filesystem is provided for "ow_space," but the script works fine when a local filesystem is provided instead.  Note that "ow_space" retrieves parameter 0, which is set to "workspace" and not "folder" since I want this parameter to also accept a file geodatabase (which is working in the script).  The error message is nonspecific and unhelpful.  How can I get arcpy.CreateFeatureclass_management to work regardless of whether ow_space is a network location or a local directory?  e.g. \\JLLORENS\Share\GIS

Below is the code in question:

Spoiler

import arcpy
from arcpy import env
from arcpy.sa import *
import os

ow_space = arcpy.GetParameterAsText(0)
in_WSheds = arcpy.GetParameterAsText(1)
file_name = arcpy.GetParameterAsText(2)
vector_extension_output = '.shp'

arcpy.CreateFeatureclass_management(ow_space, ('%s_Longest_Flowpaths_Vector%s' % (file_name, vector_extension_output)), 'POLYLINE', spatial_reference = (arcpy.Describe(in_WSheds).spatialReference))

 

0 Kudos
2 Solutions

Accepted Solutions
jllorens
New Contributor II

No, I have full write access.  

I found that using the following fixed my issue.  I cannot figure out why, since I would expect GetParameterAsText() to return a string anyways, but apparently using str() fixes the issue.

 

Replacing:

ow_space = arcpy.GetParameterAsText(0)

with:

ow_space = str(arcpy.GetParameterAsText(0))

was the fix.  If anyone can elaborate why this works, that would be awesome. 

View solution in original post

0 Kudos
MichaelBoyce
Esri Contributor

Hi @jllorens,

I agree with @JeffK, that is a very likely cause.

You may want to try converting it to "real Path" as well.

arcpy.CreateFeatureclass_management(r'{}'.format(ow_space), ('%s_Long......

That may help since "GetParameterAsText" tends to be very literal, which would mean that the network path would not be complete as far as Python is concerned.  \ is an "Escape" character, so to do the start of a network path, usually "\\" you actually need to do "\\\\".

Hope this helps,

 

Michael

View solution in original post

3 Replies
JeffK
by MVP Regular Contributor
MVP Regular Contributor

Is there a group policy governing/ access restrictions on your network that may be causing an issue?

 

 

0 Kudos
jllorens
New Contributor II

No, I have full write access.  

I found that using the following fixed my issue.  I cannot figure out why, since I would expect GetParameterAsText() to return a string anyways, but apparently using str() fixes the issue.

 

Replacing:

ow_space = arcpy.GetParameterAsText(0)

with:

ow_space = str(arcpy.GetParameterAsText(0))

was the fix.  If anyone can elaborate why this works, that would be awesome. 

0 Kudos
MichaelBoyce
Esri Contributor

Hi @jllorens,

I agree with @JeffK, that is a very likely cause.

You may want to try converting it to "real Path" as well.

arcpy.CreateFeatureclass_management(r'{}'.format(ow_space), ('%s_Long......

That may help since "GetParameterAsText" tends to be very literal, which would mean that the network path would not be complete as far as Python is concerned.  \ is an "Escape" character, so to do the start of a network path, usually "\\" you actually need to do "\\\\".

Hope this helps,

 

Michael