我正在尝试使用WinSys模块来获取系统的事件日志(windows)。但我不知道为什么以下代码不运行:
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 :(得分:0)
我可以从RegConnectRegistry文档here中看到:
computerName:string 远程计算机的名称,格式为\\ computername。如果无,则为本地 使用计算机。
因此默认计算机名称值为“。”不能在此功能中使用。好像你正在使用的Winsys版本中有bug。在我当地的Winsys版本0.5.2(取自PYPI)中,问题似乎得到纠正。
您可以使用以下代码解决此问题:
import win32api
from winsys import event_logs
moniker = "\\\\%s\\Application" % win32api.GetComputerName()
print len(event_logs.event_log(moniker))