469,327 Members | 1,230 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

winreg module, need help to understand why i'm getting exception

HI all, i found winreg module from http://www.rutherfurd.net/python/winreg/index.html
very useful and simple, instead _winreg.

But i have a problem with this module, in its iterable part.

look at the following code

key = Key(HKLM,r"SYSTEM\CurrentControlSet\Services\Tcpip \Enum")
for i in key.values:
print i.value

and that is the exception

Traceback (most recent call last):
File "D:\.Projects\python\temp.py", line 21, in <module>
for i in key.values:
File "C:\Python25\Lib\site-packages\winreg.py", line 451, in next
return self.values[self.index - 1]
File "C:\Python25\Lib\site-packages\winreg.py", line 289, in
__getitem__
name = _winreg.EnumValue(self.hkey, key)[0]
WindowsError: [Error 259] No more data is available
so there is some problem with iterate, i think
i am still a beginner, so i cant understand why this appears, and what
should i fix.

if anyone have some time to look closer to this module, i will
appreciate this very much.

thanks.

Jun 27 '08 #1
2 2062
On Apr 19, 6:20 am, hellt <Dodin.Ro...@gmail.comwrote:
HI all, i found winreg module fromhttp://www.rutherfurd.net/python/winreg/index.html
very useful and simple, instead _winreg.

But i have a problem with this module, in its iterable part.

look at the following code

key = Key(HKLM,r"SYSTEM\CurrentControlSet\Services\Tcpip \Enum")
for i in key.values:
print i.value

and that is the exception

Traceback (most recent call last):
File "D:\.Projects\python\temp.py", line 21, in <module>
for i in key.values:
File "C:\Python25\Lib\site-packages\winreg.py", line 451, in next
return self.values[self.index - 1]
File "C:\Python25\Lib\site-packages\winreg.py", line 289, in
__getitem__
name = _winreg.EnumValue(self.hkey, key)[0]
WindowsError: [Error 259] No more data is available

so there is some problem with iterate, i think
i am still a beginner, so i cant understand why this appears, and what
should i fix.

if anyone have some time to look closer to this module, i will
appreciate this very much.
The problem is not in your code, but in the module. The EnumValue()
and EnumKey() functions in the _winreg module raise WindowsError when
there are no more keys or values to retrieve. So, go inside the module
and modify that line to something like:

# There should be a for or a while loop around here
try:
name = _winreg.EnumValue(key, index)
except EnvironmentError:
Jun 27 '08 #2
Sorry, the above post is not complete. This is the rest:

# There should be a for or a while loop around here
try:
name = _winreg.EnumValue(key, index)
except EnvironmentError:
# It raises WindowsError, but the _winreg documentation
# recommends catching EnvironmentError
break
else:
# do something with 'name'
...

Anyway, I'd recommend using _winreg instead of the module you're
using, since it clearly has errors, and it's not on the standard
library.
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Pam Ammond | last post: by
8 posts views Thread by Floris van Haaster | last post: by
30 posts views Thread by Franck PEREZ | last post: by
4 posts views Thread by John please don't spam me! | last post: by
10 posts views Thread by Tom Plunket | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.