×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

CODE --> 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.

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

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.

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

(OP)
thank you for reply
i try this as below

CODE --> 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

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

escape each backslash:
d = os.path.isdir("\\\\192.168.7.9\\Import\\8") 

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

@ahmedsa2018: have you tried what i suggested? does it work or not ?

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

(OP)
sorry for late
i tried as you tell me
but still return false

CODE --> 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

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

(OP)
I think is dir working local only not remotly
are this is correct

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

But you placed the string in 2 pairs of apostrophes, it's syntax error:
d = os.path.isdir(''\\\\192.168.7.9\\Import\\8'')
 
use either
d = os.path.isdir('\\\\192.168.7.9\\Import\\8') 

or
d = os.path.isdir("\\\\192.168.7.9\\Import\\8") 

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

(OP)
so can you help me please

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

we both posted on 14:31, look what I posted, before you posted

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

(OP)
thank you for support me and i appreciate your support
i try as below

CODE --> 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

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

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 

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

Does it work with drive mapping or not ?

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

(OP)
so how to map network drive please

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

(OP)
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

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

(OP)
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

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

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

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

(OP)
it shared and give me access is denied

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

Access denied means that you don't have the right permission. You need to set it.

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

(OP)
i can open maped drive and have all permissions with full control

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

(OP)
are need to add user name and password
to nert use command
or no need
if required how to add

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

I don't know, how to set right permissions for your system (MS SQL server with Python)
But you asked this question on several other forums and I think you got the right answer here:
https://docs.microsoft.com/en-us/answers/questions...

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

(OP)
can you help me answer this question

if i use on python script as below
it will working
or no need to do that
i use code below to reach remote server

CODE --> python

import paramiko

hostname = "your-hostname"
username = "your-username"
password = "your-password"
cmd = 'your-command'

try:
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname,username=username,password=password)
    print("Connected to %s" % hostname)
except paramiko.AuthenticationException:
    print("Failed to connect to %s due to wrong username/password" %hostname)
    exit(1)
except Exception as e:
    print(e.message)    
    exit(2) 

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

(OP)
i try now to use mape network drive
it give me error 5 access is denied
using code below

CODE --> python

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) 


so i try to using domain/account name
my question i need to ask is
can access direct to remote path without using map network drive
are this possible
if possible how to do using python

CODE --> python

import paramiko

hostname = "your-hostname"
username = "your-username"
password = "your-password"
cmd = 'your-command'

try:
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname,username=username,password=password)
    print("Connected to %s" % hostname)
except paramiko.AuthenticationException:
    print("Failed to connect to %s due to wrong username/password" %hostname)
    exit(1)
except Exception as e:
    print(e.message)    
    exit(2) 

are code above allow to me export data directly from remote host
please help me

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close