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

H

hellt

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.
 
S

s0suk3

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:
 
S

s0suk3

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top