-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
getproxies() in python3.10/urllib/request.py crashes on MacOS #104578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What is the error you are seeing? We should avoid solutions that catch and ignore any |
No exceptions for me on macOS Ventura 13.3.1 with an M2 chip: Python 3.11.3 (v3.11.3:f3909b8bc8, Apr 4 2023, 20:12:10) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.request
>>> urllib.request.getproxies()
{}
>>> urllib.request.getproxies_environment()
{}
>>> urllib.request.getproxies_macosx_sysconf()
{}
>>> Python 3.10.11 (main, Apr 7 2023, 07:24:53) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.request
>>> urllib.request.getproxies()
{}
>>> urllib.request.getproxies_environment()
{}
>>> urllib.request.getproxies_macosx_sysconf()
{}
>>> |
I am using Airflow with oauth. Calling "return getproxies_environment() or getproxies_macosx_sysconf()" causes the python thread to crash (crazy!) some times, other times it just hangs there. Happens both on Macbook airs with M1 and M2 |
I believe what you are seeing is the issue described in #75999. Basically, the problem is that the Python |
That said, there doesn't seem to be any warning about this in the urllib documentation. It would probably be a good idea to add something there. |
Also, is it possible to have this condition throw a Python exception instead of aborting the process? That would make it a bit easier to understand the problem for users. |
@ned-deily Yes!! I am looking again into it and it seems it is related to that! It is quite difficult to follow because calls are all over the place, but it definitely seems like it. |
@JelleZijlstra I'm guessing that would help A LOT, definitely |
AFAIK, no. I believe the abort occurs in a lower-level macOS framework and we can't safely recover from it. |
|
@ned-deily I found there IS an option to avoid the proxy check by setting an environment variable called "NO_PROXY" (also works in lowercase) set to any value... |
Yes, using the env varuabke should avoid the problem. But I think we should at least add something to the urllib documentation about this macOS issue. It keeps biting people. |
That's correct, this is not something we can recover from. |
Could we detect it beforehand, though? I imagine the macOS code does something like |
3.12 will at least warn about using import os
import urllib.request
urllib.request.getproxies()
if os.fork() == 0: raise SystemExit("child") This prints Part of the problem with these crashes is that they don't happen consistently for all users, and can happen or not depending on code paths. In particular, the crash likely won't happen if the Something we could do is document the issue:
|
I added a number of warnings about this platform limitation in #105912, amongst others in the documentation for urllib.request. That is all we can do until Apple fixes their platform :-(. |
This is works on MacOS 13.2.1, python3.10 (using Apache Airflow and S3 operators). |
Bug report
There is a bug regarding the getproxies() function in the python3.10/urllib/request.py module. The issue occurs specifically when running the function on MacOS with an M1 or M2 CPU, where it results in a crash.
To address this problem, I propose a simple solution involving a try-except block to handle the potential errors.
Currently, the code looks as follows:
Here's the proposed solution:
By implementing this change, the getproxies() function will first attempt to retrieve the proxies using getproxies_environment(). If an exception is raised, indicating a failure on MacOS with M1/M2 CPU, it will then fall back to getproxies_macosx_sysconf(). In case of any additional exceptions, an empty dictionary {} will be returned.
Environment
The text was updated successfully, but these errors were encountered: