{"id":7597,"library":"pypac","title":"PyPAC - Python Proxy Auto-Config","description":"PyPAC is a Python library that provides proxy auto-config (PAC) and proxy auto-discovery (WPAD) functionality. It enables applications to automatically determine and use the correct proxy server based on a PAC script, crucial for environments requiring complex proxy logic. The current version is 0.17.2, and it maintains a moderate release cadence, with several minor releases annually addressing bug fixes and minor enhancements.","status":"active","version":"0.17.2","language":"en","source_language":"en","source_url":"https://github.com/carsonyl/pypac","tags":["proxy","pac","wpad","network","requests","http"],"install":[{"cmd":"pip install pypac","lang":"bash","label":"Install core library"},{"cmd":"pip install pypac requests","lang":"bash","label":"Install with requests integration"}],"dependencies":[{"reason":"Required for PACSession integration with the popular requests library.","package":"requests","optional":true},{"reason":"Required for PAC script evaluation on Python 2.7.","package":"dukpy","optional":true}],"imports":[{"symbol":"PACProxyResolver","correct":"from pypac import PACProxyResolver"},{"symbol":"PACSession","correct":"from pypac import PACSession"}],"quickstart":{"code":"from pypac import PACSession\nimport requests\n\ntry:\n    # Auto-discovers PAC files or manually specify via PACSession(pac_url='...')\n    with PACSession() as session:\n        # Example usage with a public IP checker (ensure it's HTTP/HTTPS)\n        response = session.get('http://httpbin.org/ip')\n        response.raise_for_status()\n        print(f\"Using PACSession, IP is: {response.json()['origin']}\")\nexcept requests.exceptions.RequestException as e:\n    print(f\"Request failed: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to use PyPAC's `PACSession` to automatically resolve and apply proxy settings for `requests` calls. `PACSession` handles PAC file discovery (e.g., via WPAD) and proxy resolution transparently. If no PAC file is found via auto-discovery, it will default to direct connections."},"warnings":[{"fix":"Rely on `PACSession` to manage proxies automatically. If you need to inspect proxy usage, check `response.request.proxy_url` after a request.","message":"When using `PACSession` for `requests` integration, do not attempt to set `session.proxies` manually. `PACSession` transparently handles proxy resolution and setting, and directly modifying `session.proxies` will override or conflict with its functionality.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If auto-discovery fails, explicitly provide the PAC file URL or path: `PACSession(pac_url='http://your.proxy.com/proxy.pac')` or `PACProxyResolver(url='...')`.","message":"PAC file auto-discovery (WPAD) can be unreliable or disabled in some network environments (e.g., corporate networks, firewalls). If `PACSession` or `PACProxyResolver` cannot find a PAC file, it will fall back to a direct connection, which might not be desired.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate to Python 3. If Python 2.7 is mandatory, ensure `dukpy>=0.2.3` is installed and be aware of potential platform-specific issues.","message":"Python 2.7 support is deprecated and requires the `dukpy` library for PAC script evaluation, which itself has specific installation and versioning requirements for older Python. For modern use, Python 3 is strongly recommended.","severity":"gotcha","affected_versions":"0.16.2 and older on Python 2.7"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Provide the PAC file's URL or local path explicitly: `resolver = PACProxyResolver(url='http://your.proxy.com/proxy.pac')` or `session = PACSession(pac_url='file:///path/to/proxy.pac')`.","cause":"PyPAC could not locate a PAC file through auto-discovery (WPAD) or no explicit PAC URL/path was provided.","error":"pypac.parser.proxy_resolver.ProxyResolutionError: No PAC file found."},{"fix":"Do not attempt to set or access `session.proxies` directly. `PACSession` automatically applies the resolved proxy. If you need to see what proxy was used, inspect `response.request.proxy_url` after a request has been made.","cause":"`PACSession` from `pypac` is designed to handle proxy resolution internally and does not expose a settable `.proxies` attribute like a standard `requests.Session` object.","error":"AttributeError: 'PACSession' object has no attribute 'proxies'"},{"fix":"`PACSession` integrates with `requests`. Install it with: `pip install requests` (or `pip install pypac requests`).","cause":"You are trying to use `pypac.PACSession` but the `requests` library is not installed.","error":"ModuleNotFoundError: No module named 'requests'"}]}