Shailesh Kumar wrote: > Hi, > I am facing a problem with network paths which contain non-ascii > characters when trying to map them. > > More precisely, the location contains Korean characters. > location = ur'\\baton1\TestStreams\shailesh\게댜ㅕㅔ걷;어니;ㅓ' > > WNetAddConnection2 function expects string type as remoteName argument. > > A simple call certainly fails: > win32wnet.WNetAddConnection2( > win32netcon.RESOURCETYPE_DISK, > None, location, None, > None, None) > Traceback (most recent call last): > File "D:\eclipseworkspaces\training\pytraining\win32networkstuff\unc.py", > line 66, in ? > None, None) > UnicodeEncodeError: 'ascii' codec can't encode characters in position > 30-44: ordinal not in range(128) > > > I couldn't figure out the right encoding for the UNICODE string. I tried both > 'utf8' and 'mbcs' encodings, something like: > > win32wnet.WNetAddConnection2( > win32netcon.RESOURCETYPE_DISK, > None, location.encode('utf8'), None, > None, None) > > Traceback (most recent call last): > File "D:\eclipseworkspaces\training\pytraining\win32networkstuff\unc.py", > line 66, in ? > None, None) > pywintypes.error: (53, 'WNetAddConnection2', 'The network path was not > found.') > > > Sometimes 'Access is Denied' string is also reported. > > What is the right way to handle this case? > Your help is highly appreciated. > > I am running Python 2.4.4 on Win XP Pro with pywin32-209 revision. > > With regards, > -Shailesh
The win32wnet functions use plain strings for compatibility with Win98. You should be able to use win32net.NetUseAdd instead, which uses unicode. Roger _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32