On 6/15/07, Wiley Thomas <[EMAIL PROTECTED]> wrote: > I'm trying to write a script to open a file on our (windows) network. The > file is located on a machine that is not part of the domain and requires a > separate user id and password to access. I tried using urllib2 and the > password_manager to authenticate but as some point urllib2 sees I'm trying > to access a local file and passes it off to os. The error message I get is: > > "WindowsError: [Error 1326] Logon failure: unknown user name or bad > password: <file path. > > Does anyone know of a better approach.
Urllib2 is used for making HTTP/FTP requests. When you open a file on a network share, the networking is handled by Windows; as far as Python is concerned, it's treated the same as a local file. You could try something like this (untested): os.system(r"NET USE \\computer\share password /USER:username") # do something with file os.system(r"NET USE \\computer\share /DELETE") That should authenticate and de-authenticate you properly, but it seems like a fragile way of doing it -- for one thing, I think it would grant access to any other program running under your login session. There may be a better way of doing this using the Windows API. Alternatively, depending on your application, you might want to consider using a simple web or FTP server. -- David -- http://mail.python.org/mailman/listinfo/python-list