2015-02-24 48 views
0

我必須通過web2py中,我需要使用驗證和登記機,並將其存儲到數據庫中建立一個形式。驗證沒有通過。我總是得到錯誤,「休斯頓似乎有機器名稱或超級密碼問題」。如果我在web2py環境外運行paramiko腳本,它工作正常。請幫忙。的web2py的paramiko與對SSH功能

形式的詳情:

db.define_table('nsksystem', 
    Field('nskmachinename', length=128, requires = IS_NOT_EMPTY(error_message='Machine Name cant be empty'), label = T('Machine Name')), 
    Field('nskpassword', 'password', length=512,readable=False, label=T('Machine Password')), 
    Field('confirmnskpassword', 'password', length=512,readable=False, label=T('Confirm Machine Password'))  ) 

控制器:default.py(用於插入之前驗證表單插入)

def machinevalidate(form): 
    host = form.vars.nskmachinename 
    user ='superman' 
    pwd = form.vars.nskpassword 

    ssh = paramiko.SSHClient() 
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())  
    try: 
    ssh.connect(host, username=user,password=pwd) 
    return True 
    except Exception, e: 
    form.errors.nskpassword = 'Houston there seems to be a problem with Machine name or super password' 
finally: 
    ssh.close() 

控制器:default.py(用於插入到數據庫)

@auth.requires_login() 
def machine(): 
form = SQLFORM(db.nsksystem) 
if form.process(onvalidation=machinevalidate).accepted: 
    response.flash = 'The machine is now registered to the user.' 
elif form.errors: 
    response.flash = 'Form has errors' 
else: 
    response.flash = 'Please register a machine to your ID' 
return dict(form=form) 

我刪除了try/catch語句,這裏的建議後是錯誤的回溯。我有Lib/ctypes下的wintypes.py。但仍然無法弄清楚爲什麼會有導入錯誤。

Traceback (most recent call last): 
    File "gluon/restricted.py", line 224, in restricted 
    File "C:/web2py/applications/click/controllers/default.py", line 53, in <module> 
    File "gluon/globals.py", line 393, in <lambda> 
    File "gluon/tools.py", line 3444, in f 
    File "C:/web2py/applications/click/controllers/default.py", line 39, in machine 
    if form.process(onvalidation=machinevalidate).accepted: 
    File "gluon/html.py", line 2303, in process 
    File "gluon/html.py", line 2240, in validate 
    File "gluon/sqlhtml.py", line 1461, in accepts 
    File "gluon/html.py", line 2141, in accepts 
    File "gluon/html.py", line 146, in call_as_list 
    File "C:/web2py/applications/click/controllers/default.py", line 33, in machinevalidate 
    ssh.connect(host, username=user,password=pwd) 
    File "C:\Python27\lib\site-packages\paramiko\client.py", line 307, in connect 
    look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host) 
File "C:\Python27\lib\site-packages\paramiko\client.py", line 456, in _auth 
self._agent = Agent() 
    File "C:\Python27\lib\site-packages\paramiko\agent.py", line 332, in __init__ 
from . import win_pageant 
File "gluon/custom_import.py", line 105, in custom_importer 
    File "C:\Python27\lib\site-packages\paramiko\win_pageant.py", line 25, in <module> 
    import ctypes.wintypes 
    File "gluon/custom_import.py", line 105, in custom_importer 
ImportError: No module named wintypes 
+0

我會通過擺脫那個'try' /'except'的開始,讓例外落空,所以你可以看到什麼異常實際上是。 – 2015-02-24 07:45:29

+0

刪除try/catch後發佈錯誤日誌。它給出了一個導入錯誤。但wintypes模塊在我機器的ctypes下。 – May 2015-02-24 09:02:44

回答

0

得到了解決方案... 我正在使用web2py的編譯版本。當我使用源代碼時,模塊的導入不再是頭疼。謝謝安德魯·馬吉給了一擡起頭......