Python的使用wnet_connect(主机,用户名=无,密码=无)

问题描述:

我想连接到一个未列在DNS中的服务器,它只是一个带有IP的服务器。Python的使用wnet_connect(主机,用户名=无,密码=无)

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

它无法连接到服务器或任何机器:

我使用这个代码没有得到运气如果它不在DNS中。