Python使用wnet_connect(host, username=None, password=None)
我正在尝试连接一个服务器,这个服务器没有在DNS上列出,它只是一个有IP地址的服务器。
我用下面的代码连接,但是没有成功:
netpath = r'\\10.5.1.22\Products'
networkPath = netpath
unc = ''.join(['\\\\', host])
print unc
try:
win32wnet.WNetAddConnection2(0, None, unc, None, username, password)
except Exception, err:
if isinstance(err, win32wnet.error):
#Disconnect previous connections if detected, and reconnect.
if err[0] == 1219:
win32wnet.WNetCancelConnection2(unc, 0, 0)
return wnet_connect(host, username, password)
raise err
在这种情况下,有没有更好的连接方法?我使用的是Python 2.7。
1 个回答
0
如果某台服务器或机器不在DNS里,就无法连接上它。