Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory path display false as not exist although it exist with full control permission ?

Status
Not open for further replies.

ahmedsa2018

Programmer
Apr 25, 2018
67
0
0
EG
I working on script running on sql server 2019 using python 3.10 .

I have directory path \\192.168.7.9\Import\8 and can

write and read to files and delete and create files on

this directory path \\192.168.7.9\Import\8.

my issue when run script python on sql server 2019

it return false

but it must return true because directory path exist.

this path have permissions everyone and administrator and system full control read and write and delete .

script python

Python:
declare @ExportPath varchar(max)='\\192.168.7.9\Import\8'
EXEC sp_execute_external_script
@language =N'Python',
@script=N'
import os
d = os.path.isdir(ExportFilePath)
print(d)'
,@params = N'@ExportFilePath NVARCHAR(MAX)'
,@ExportFilePath = @ExportPath

Expected result is True

from sql server it return true as exist but from python script it return false for same server and same user.

correct_result_is_true_wt9j6h.png
 
What is ExportFilePath set to? As it stands, it is blank. Blank does not exist so the code is doing what you told it.

Just print ExportFilePath within the python code to see if it is set to what you think it ought to be set to. Maybe you need quotes around the string.
 
thank you for reply
i try this as below
Python:
EXEC sp_execute_external_script
@language =N'Python',
@script=N'
import os
d = os.path.isdir(''\\192.168.7.9\Import\8'')
print(d)'
still return false as not exist
i test this remote server path from same sql server on same machine for same user and on same sql server version
by Master.dbo.xp_fileexist it return 1 as exist

so what is issue and how to solve it please
 
escape each backslash:
[pre]d = os.path.isdir("\\\\192.168.7.9\\Import\\8")[/pre]
 
@ahmedsa2018: have you tried what i suggested? does it work or not ?
 
sorry for late
i tried as you tell me
but still return false
Python:
EXEC sp_execute_external_script
@language =N'Python',
@script=N'
import os
d = os.path.isdir(''\\\\192.168.7.9\\Import\\8'')
print(d)'
it return false as not exist
so what i do to solve issue
 
I think is dir working local only not remotly
are this is correct
 
But you placed the string in 2 pairs of apostrophes, it's syntax error:
[pre]d = os.path.isdir([highlight #FCE94F]'[/highlight][highlight #F57900]'[/highlight]\\\\192.168.7.9\\Import\\8[highlight #F57900]'[/highlight][highlight #FCE94F]'[/highlight])
[/pre]
use either
[pre]d = os.path.isdir([highlight #FCE94F]'[/highlight]\\\\192.168.7.9\\Import\\8[highlight #FCE94F]'[/highlight])[/pre]
or
[pre]d = os.path.isdir([highlight #FCE94F]"[/highlight]\\\\192.168.7.9\\Import\\8[highlight #FCE94F]"[/highlight])[/pre]
 
we both posted on 14:31, look what I posted, before you posted
 
thank you for support me and i appreciate your support
i try as below

Python:
EXEC sp_execute_external_script
@language =N'Python',
@script=N'
import os
d = os.path.isdir("\\\\192.168.7.9\\Import\\8")
print(d)'

also not working and return false as not exist

 
other option could be something like this: first map the shared source as network drive and then check if it's directory

Code:
import os
result = os.system("net use S: \\\\192.168.7.9\\Import\\8")
print("result =", result)
d = os.path.isdir("S:")
print("d =", d)

results should be:
Code:
result = 0
d = True
 
after map
it give me result
STDERR message(s) from external script:
System error 67 has occurred.

The network name cannot be found.


STDOUT message(s) from external script:
result = 2
d = False
 
last try i create mapped drive
i get error
STDERR message(s) from external script:
System error 5 has occurred.

Access is denied.


STDOUT message(s) from external script:
result = 2
d = False
 
The error "The network name cannot be found." indicates that your PC does not know the other PC (192.168.7.9) which shared source you want to access (\Import\8\). Check if you see from your PC the PC with IP address 192.168.7.9 and if it has enabled share Import
 
Access denied means that you don't have the right permission. You need to set it.

 
i can open maped drive and have all permissions with full control
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top