Topic: Python - map widows network drive (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=30663" title="Pages that link to Topic: Python - map widows network drive (Page 1 of 1)" rel="nofollow" >Topic: Python - map widows network drive <span class="small">(Page 1 of 1)</span>\

 
CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 11-20-2008 01:46

Not sure where to post this so...

I am trying to write a python script that mounts a windows network share. Here is the code that I have

code:
import win32wnet
from win32netcon import RESOURCETYPE_DISK as DISK

drive_letter = "K:"
path = "\\server\share"
win32wnet.WNetAddConnection2(DISK, drive_letter, path)



However, it says :

quote:

pywintypes.error : ('67','WNetAddConnection2','The Network name can not be found' )



I know that I have the right path. Opening Explorer and typing that in, works. So, I am not sure what the problem is.

Any help is appreciated. Thanks in advance!

Later,

C:\

(Edited by CPrompt on 11-20-2008 01:47)

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 11-20-2008 01:52

eigh...I figured it out

I need this

code:
path="\\\\server\\share"



Thanks anyway

Later,

C:\

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 11-20-2008 16:14

OK...how can I suppress the pywintypes errors?

If the mapped drive is there, then the code fails and logs this:

quote:

pywintypes.error: (85, 'WNetAddConnection2', 'The local device name is already in use.')



I have tried:

code:
try:
   win32wnet.WNetAddConnection2(DISK,scans_drive,scans_path)
except pywintypes.error,details:
   err_code=details[0]
   print "Error"



but it says that

quote:

'pywintypes' is not defined



I've googles for how to work with pywintype errors but it hasn't worked yet. Any ideas?

Thanks in advance!

Later,

C:\

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 11-20-2008 16:28

nevermind again....

I just needed to import the pywintypes modules and I could handle it just fine

Later,

C:\

kuckus
Paranoid (IV) Mad Librarian

From: ber/ger
Insane since: Dec 2001

posted posted 11-20-2008 20:29

hmm... seems I'm late again.

*grabs popcorn*

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 11-21-2008 14:08

no problem. I'm glad I figured it out on my own though. Another 14 minutes and I wouldn't have had to post that last question

Later,

C:\

Veneficuz
Paranoid (IV) Inmate

From: A graveyard of dreams
Insane since: Mar 2001

posted posted 11-21-2008 15:39

I think your first problem with the extra slashes would have been solved by using Python's raw string syntax:

code:
path = r"\\server\share"



_________________________
- the Golden Ratio

lallous
Maniac (V) Inmate

From: Lebanon
Insane since: May 2001

posted posted 11-22-2008 00:32

Hi CPrompt,

Why do you need that in Phyton, and not a batch file?

--
Regards,
Elias

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 11-22-2008 03:18
quote:

lallous said:

Hi CPrompt,Why do you need that in Phyton, and not a batch file?--Regards,Elias



because I needed to do this and I am trying to learn Python
It does a little more than map the drive though.

Thanks for the comment Veneficuz. I'll give that a go.

Later,

C:\



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu