netinvent / windows_tools

Collection of various interfaces for Windows functionality in a Pythonic way
BSD 3-Clause "New" or "Revised" License
63 stars 15 forks source link

windows_tools.updates.get_windows_updates not working #11

Closed negativeproton closed 1 year ago

negativeproton commented 1 year ago

With the current project state and the setup described in https://github.com/netinvent/windows_tools/issues/10:

using python.exe -m pip install .\dist\windows_tools.updates-2.0.5-py3-none-any.whl and the code snippet from the readme.md:

>>> import windows_tools.updates
>>> result = windows_tools.updates.get_windows_updates(filter_duplicates=True, include_all_states=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\windows_tools\updates\__init__.py", line 221, in get_windows_updates
    reg_update_list = get_windows_updates_reg(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\windows_tools\updates\__init__.py", line 184, in get_windows_updates_reg
    "date": key["InstallLocation"]["last_modified"],
KeyError: 'last_modified'

To check if that isn't caused because the system never had updates installed, I installed and rebooted: "2023-04 Update for Windows 11 Version 22H2 for x64-based Systems (KB4023057)". Expected behavior would be that it shows this update in the output.

(Also the case in release v2.3.0, I believe to remember)

deajan commented 1 year ago

Cannot reproduce. Code works for me. I'm somehow blind fixing here. Could you test with current master (did commit https://github.com/netinvent/windows_tools/commit/725fd1b36b9e3c0e10b7349faf3533fd2438a0a5)

If this doesn't work, I'll need a part of the registry that creates the problem.

negativeproton commented 1 year ago

Again, thank you for the swift response :).

the new error is:

>>> import windows_tools.updates
>>> result = windows_tools.updates.get_windows_updates(filter_duplicates=True, include_all_states=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\windows_tools\updates\__init__.py", line 229, in get_windows_updates
    reg_update_list = get_windows_updates_reg(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\windows_tools\updates\__init__.py", line 199, in get_windows_updates_reg
    kb = KB_REGEX.search(key["InstallLocation"]["value"])
KeyError: 'value'

same for python11:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\windows_tools\updates\__init__.py", line 229, in get_windows_updates
    reg_update_list = get_windows_updates_reg(
                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\windows_tools\updates\__init__.py", line 199, in get_windows_updates_reg
    kb = KB_REGEX.search(key["InstallLocation"]["value"])
                         ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'value'

I understand that having to blind-fix isn't the ideal situation.

How do I provide the helpful and necessary part of the registry?

Alternatively and somewhat better, replicating the whole system where the error exists requires but a few minutes of manual labor

one can get this free windows 11 virtualbox dev vm from: https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/ (and 3 other options)

then in cmd or ps:

winget install --id=Python.Python.3.11 -e

(updated for newest version) in freshly opened cmd or ps:

python -m pip install --upgrade pip

winget install --id Git.Git -e --source winget

in freshly opened cmd or ps:

git clone https://github.com/netinvent/windows_tools.git

cd .\windows_tools\ python.exe -m pip install wheel python.exe setup.py bdist_wheel python.exe -m pip install .\dist\windows_tools.updates-2.0.6-py3-none-any.whl

that should be it

deajan commented 1 year ago

Again, thank you for the detailed report and solution ;)

I've downloaded and played with the Win11 VM. Oh gosh I hate the winget syntax. Fixed the issue and updated a couple of other things btw.

When developping, I don't create dists but merely do the following:

c:
cd git\windows_tools
SET PYTHONPATH=c:\git\windows_tools
python -m pytest tests\test_updates.py

Anyway, I think a pip release is deserved. If no other issues raise next week, I'll make a new release.

negativeproton commented 1 year ago

Thank you so much for the solution and the updates :)

It works for me! Just FYI, I'll keep using the described Win11 virtualbox dev VM