carsonyl / pypac

Find and use proxy auto-config (PAC) files with Python and Requests.
https://pypac.readthedocs.io
Apache License 2.0
71 stars 19 forks source link

When get_pac returns None, there is no way to tell if there is no PAC, or if error occurred #76

Open KarelChanivecky opened 1 year ago

KarelChanivecky commented 1 year ago

In download_pac, when an error occurs during an HTTP request, the error is ignored, and the next URL is attempted. At the end, if all URLs failed with error, the function returns None. It can be implied from this function that an error has occurred. If the list of URLs contained at least one URL, it should be expected that a response is available. However, it cannot be implied from get_pac, as perhaps PAC is not configured at all. Hence, either:

KarelChanivecky commented 1 year ago

Today, I found there is a registry value from which one can infer what are the available proxy modes. Given this value, it could be evaluated whether the WPAD or the PAC URL should be evaluated at all. In case that they did, then one should expect one, hence failing of those request would deserve to be an exception:

https://stackoverflow.com/questions/1674119/what-key-in-windows-registry-disables-ie-connection-parameter-automatically-det

I implemented the suggestion above in our code base. I could contribute this here if the maintainers agree.

carsonyl commented 1 year ago

That stackoverflow post is a very good find. But I am not sure about the idea of get_pac() being changed to raise errors by default, due to compatibility. The original idea was that missing PAC should not raise an error because the operating system doesn't do it either.

KarelChanivecky commented 1 year ago

How about adding an API function to help the user evaluate if PAC/wpad is configured to be used?

This could be used to determine whether a PAC script is to be expected as a return from get_pac