Fix Invoke-WebRequest IDictionary cast error#292
Fix Invoke-WebRequest IDictionary cast error#292l3tchupkt wants to merge 1 commit intopython:mainfrom
Conversation
This is worth fixing.
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. |
|
Yeah, The original version keeps all headers and just turns null values
into empty strings, so nothing gets dropped. With the suggested change, any
null or “falsy” value (like empty strings, 0, or false) gets skipped
entirely, which means some headers might not be sent at all. So it’s not
exactly the same behavior.
|
|
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. |
Originally fixed in #292 Co-authored-by: badassletchu@gmail.com
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)-Headersparameter forInvoke-WebRequeststrictly requires aSystem.Collections.IDictionary(Hashtable). When headers are passed from Python as JSON and parsed viaConvertFrom-Json, PowerShell returns aPSCustomObject, which fails the type-binding check.PSCustomObjectinto 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.splitrootFallback (src/manage/pathutils.py)pathutils.pyreimplementation relied onos.path.splitroot, a function only introduced in Python 3.11. This caused immediate crashes on older stable runtimes like Python 3.10._splitroothelper function that usesntpath.splitdriveas a fallback whenos.path.splitrootis unavailable. This maintains the project's goal of high performance with minimal imports while ensuring broad version compatibility.3. Verification Summary
test_powershell_urlretrieve,test_powershell_urlopen, andtest_powershell_urlretrieve_authall pass on a Windows 10/11 environment running Python 3.10 and PowerShell 5.1.urlliborwinhttpdownload paths.