Fix issue #2096: Handle URLs with embedded HTTP credentials in _load_image by nMaroulis · Pull Request #2102 · abetlen/llama-cpp-python
References:
Fixes Issue #2096
Overview:
Fixes an issue where _load_image fails on URLs containing HTTP credentials (e.g., http://user:pass@example.com/image.jpg) and raises http.client.InvalidURL.
Solution:
- Detect URLs with embedded credentials.
- Use HTTPPasswordMgrWithDefaultRealm + HTTPBasicAuthHandler from urllib.request.
- Strip credentials from the URL before opening.
- Imports remain inside the function to match library style.
Test plan:
Verified that _load_image now works with:
- Normal URLs
- URLs with embedded credentials
- data: URLs