Skip to content

Fix Invoke-WebRequest IDictionary cast error#292

Closed
l3tchupkt wants to merge 1 commit intopython:mainfrom
l3tchupkt:main
Closed

Fix Invoke-WebRequest IDictionary cast error#292
l3tchupkt wants to merge 1 commit intopython:mainfrom
l3tchupkt:main

Conversation

@l3tchupkt
Copy link
Copy Markdown
Contributor

Description

This PR addresses a critical failure in the PowerShell-based download fallback and restores compatibility for systems running Python versions earlier than 3.11.

1. PowerShell Header Binding Fix (src/manage/urlutils.py)

  • Root Cause: In Windows PowerShell 5.1, the -Headers parameter for Invoke-WebRequest strictly requires a System.Collections.IDictionary (Hashtable). When headers are passed from Python as JSON and parsed via ConvertFrom-Json, PowerShell returns a PSCustomObject, which fails the type-binding check.
  • Fix: The PowerShell script has been updated to manually coerce the PSCustomObject into a true Hashtable (@ {}) by iterating over its properties. This ensures the download fallback remains robust across all Windows installations.

2. Python 3.10 os.path.splitroot Fallback (src/manage/pathutils.py)

  • Root Cause: The current pathutils.py reimplementation relied on os.path.splitroot, a function only introduced in Python 3.11. This caused immediate crashes on older stable runtimes like Python 3.10.
  • Fix: Implemented a _splitroot helper function that uses ntpath.splitdrive as a fallback when os.path.splitroot is unavailable. This maintains the project's goal of high performance with minimal imports while ensuring broad version compatibility.

3. Verification Summary

  • PowerShell Tests: Verified that test_powershell_urlretrieve, test_powershell_urlopen, and test_powershell_urlretrieve_auth all pass on a Windows 10/11 environment running Python 3.10 and PowerShell 5.1.
  • Regression Testing: Confirmed that the fix does not interfere with the primary urllib or winhttp download paths.

@zooba
Copy link
Copy Markdown
Member

zooba commented Mar 30, 2026

In Windows PowerShell 5.1, the -Headers parameter for Invoke-WebRequest strictly requires a System.Collections.IDictionary (Hashtable).

This is worth fixing.

Python 3.10 os.path.splitroot Fallback

This is not relevant. PyManager is released as an app, not a library, and only needs to be compatible with the version of Python that it carries with it. That's never going to be 3.10, so we can ignore fallbacks.

In general, try and keep separate fixes in separate PRs (and feel free to create issues first if there are any questions about applicability). We can't merge this until the unnecessary changes are removed.

@l3tchupkt
Copy link
Copy Markdown
Contributor Author

l3tchupkt commented Mar 30, 2026 via email

@zooba
Copy link
Copy Markdown
Member

zooba commented Mar 31, 2026

I needed the relevant part of this fix to unblock other work, so I recreated a new PR #297 with just the bit we're taking. Hopefully the co-authored-by label will work properly to send credit your way - definitely not trying to steal your work, just can't do anything else without this fix.

@zooba zooba closed this Mar 31, 2026
zooba added a commit that referenced this pull request Mar 31, 2026
Originally fixed in #292

Co-authored-by: badassletchu@gmail.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants