2011-06-10 88 views
0

我想使用WinSys模块来获取我的系统(Windows)的事件日志。但我不知道为什么下面的代码犯规运行:帮助winsys模块

from winsys import event_logs 
print len (event_logs.event_log ("Application")) 

for logs in event_logs.event_logs(computer='.'): 
    print logs 

这些产量错误

Traceback (most recent call last): 
    File "Q:\8th sem\python\untitled1.py", line 10, in <module> 
    event_logs.event_log("Application") 
    File "C:\Python26\lib\site-packages\winsys\event_logs.py", line 376, in event_log 
    return EventLog (computer, log_name) 
    File "C:\Python26\lib\site-packages\winsys\event_logs.py", line 119, in __init__ 
    key = registry.registry (self.REG_ROOT % self.computer).get_key (self.name) 
    File "C:\Python26\lib\site-packages\winsys\registry.py", line 503, in registry 
    return Registry.from_string (root, access=access, accept_value=accept_value) 
    File "C:\Python26\lib\site-packages\winsys\registry.py", line 485, in from_string 
    hKey, moniker, value = cls._from_string (string, access, accept_value) 
    File "C:\Python26\lib\site-packages\winsys\registry.py", line 469, in _from_string 
    hRoot = wrapped (win32api.RegConnectRegistry, computer, root) 
    File "C:\Python26\lib\site-packages\winsys\exc.py", line 44, in _wrapped 
    raise exception (errno, errctx, errmsg) 
winsys.registry.x_registry: (53, 'RegConnectRegistry', 'The network path was not found.') 

有什么我思念?

回答

0

,我可以从RegConnectRegistry文档here看到:

computerName : string The name of the remote computer, of the form \\computername. If None, the local computer is used.

因此默认计算机名称值 “”不能用于此功能。看起来你正在使用的Winsys版本中存在错误。在我本地的Winsys版本0.5.2(取自PYPI)中,问题似乎得到纠正。

可以解决此问题通过使用下面的代码:

import win32api 
from winsys import event_logs 
moniker = "\\\\%s\\Application" % win32api.GetComputerName() 
print len(event_logs.event_log(moniker)) 
+0

我安装了winsys 0.5.2版本,并使用上面的代码,但它仍然不工作 – ashokadhikari 2011-06-12 05:31:49

+0

“代码”回溯(最近最后一次通话): 文件“Q:\ 8th sem \ python \ untitled1.py”,第4行,在 print len(event_logs.event_log(moniker)) 文件“C:\ Python26 \ lib \ site-packages \ winsys \ event_logs.py“,第385行,在event_log中 返回EventLog(计算机或”。“,log_name) 文件”C:\ Python26 \ lib \ site-packages \ winsys \ event_logs.py“,行123,in __init__ core._WinSysObject .__ init__(self) AttributeError:class _WinSysObject没有属性'__init __''代码' – ashokadhikari 2011-06-12 05:34:54

+0

这个问题已经在Winsys SVN trunk中修复了,但是你可以通过打开C:\ Python26 \ lib \ site-packages \ winsys \ core.py文件并将第13行更改为:class _WinSysObject(object):' – Bahus 2011-06-13 14:02:24