Have you ever encountered a frustrating situation where your browser can access a local service, but your terminal and IDE cannot? Recently, I faced this exact issue while trying to access a ComfyUI API running on 127.0.0.1:8188.
The Problem
- What worked: Browser with proxy settings could access the local service
- What didn’t work: VSCode, terminal, and
curlcommands couldn’t reach127.0.0.1:8188 - What I tried: Cleared system and IDE proxy settings, removed
HTTP_PROXYandHTTPS_PROXYenvironment variables
Despite confirming that echo %HTTP_PROXY% and echo %HTTPS_PROXY% returned empty values, the issue persisted.
The Solution: Let Your Tools Tell You What They See
Sometimes the best approach is to let your applications reveal their own proxy configuration. Here’s a Python script that helped me diagnose the issue:
import os
import urllib.request
print("--- Checking Environment Variables from Python's perspective ---")
# os.environ is how Python sees all environment variables
print(f"HTTP_PROXY: {os.environ.get('HTTP_PROXY')}")
print(f"HTTPS_PROXY: {os.environ.get('HTTPS_PROXY')}")
print("\n--- Checking what proxies urllib automatically detects ---")
# getproxies() shows what urllib will use by default
print(urllib.request.getproxies())
What This Reveals
The urllib.request.getproxies() function shows you exactly what proxy settings your Python environment detects, even when environment variables appear clean. This often reveals:
- Registry-based proxy settings (Windows)
- System-wide proxy configurations
- Application-specific proxy settings that override environment variables
The Fix: Explicitly Disable Proxies
If you find unwanted proxy settings, you can force urllib (and applications that use it) to bypass proxies entirely:
# Create a proxy handler with no proxies
proxy_handler = urllib.request.ProxyHandler({})
opener = urllib.request.build_opener(proxy_handler)
urllib.request.install_opener(opener)
Key Takeaway
When troubleshooting network connectivity issues, don’t just rely on environment variables and system settings. Use your application’s own introspection capabilities to understand what it actually sees. This approach often reveals hidden proxy configurations that standard troubleshooting methods miss.
Pro tip: Always check what your specific tools and libraries detect, not just what the system claims to be configured.