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
Remove import from deprecated urllib3.contrib.pyopenssl #331
Comments
If `requests-toolbelt` doesn't stop importing the deprecated module, we may have to stop using it. Refs: * requests/toolbelt#331 * urllib3/urllib3#2680
The urllib3 warning is only printed if a package named urllib3-secure-extra is installed in your virtualenv. The imports don't have any effect on this. See https://youtu.be/_jUXdX8e9Wg for a more complete explanation. And indeed simply installing In other words, there's no bug in request-toolbelt. You need to understand why you have |
urllib3-secure-extra is not installed, but I do have pyOpenSSL installed. As urllib3/urllib3#2680 describes, it's not just the [secure] extra that was deprecated but also: "'urllib3.contrib.pyopenssl' module is deprecated and will be removed in a future release of urllib3 2.x." I tried this with a fresh project/virtualenv:
|
Thanks, I was focused on the extra and forgot about pyopenssl itself, sorry! I am seeing two options:
|
Ping. This is major pain the butt as it causes pytest to crash when trying to run e.g. hypothesis test suite when requests-toolbelt just happens to be imported indirectly: ERROR: while parsing the following warning configuration:
ignore::hypothesis.errors.NonInteractiveExampleWarning
This error occurred:
Traceback (most recent call last):
File "/usr/lib/pypy3.9/site-packages/_pytest/config/__init__.py", line 1639, in parse_warning_filter
category: Type[Warning] = _resolve_warning_category(category_)
File "/usr/lib/pypy3.9/site-packages/_pytest/config/__init__.py", line 1677, in _resolve_warning_category
m = __import__(module, None, None, [klass])
File "/tmp/portage/dev-python/hypothesis-6.56.1/work/hypothesis-hypothesis-python-6.56.1/hypothesis-python-pypy3/install/usr/lib/pypy3.9/site-packages/hypothesis/__init__.py", line 56, in <module>
run()
File "/tmp/portage/dev-python/hypothesis-6.56.1/work/hypothesis-hypothesis-python-6.56.1/hypothesis-python-pypy3/install/usr/lib/pypy3.9/site-packages/hypothesis/entry_points.py", line 63, in run
hook = entry.load()
File "/usr/lib/pypy3.9/importlib/metadata.py", line 86, in load
module = import_module(match.group('module'))
File "/usr/lib/pypy3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<builtin>/frozen importlib._bootstrap_external", line 865, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/usr/lib/pypy3.9/site-packages/pydantic/_hypothesis_plugin.py", line 53, in <module>
import email_validator
File "/usr/lib/pypy3.9/site-packages/email_validator/__init__.py", line 6, in <module>
import dns.resolver
File "/usr/lib/pypy3.9/site-packages/dns/resolver.py", line 38, in <module>
import dns.query
File "/usr/lib/pypy3.9/site-packages/dns/query.py", line 43, in <module>
from requests_toolbelt.adapters.source import SourceAddressAdapter
File "/usr/lib/pypy3.9/site-packages/requests_toolbelt/__init__.py", line 12, in <module>
from .adapters import SSLAdapter, SourceAddressAdapter
File "/usr/lib/pypy3.9/site-packages/requests_toolbelt/adapters/__init__.py", line 12, in <module>
from .ssl import SSLAdapter
File "/usr/lib/pypy3.9/site-packages/requests_toolbelt/adapters/ssl.py", line 16, in <module>
from .._compat import poolmanager
File "/usr/lib/pypy3.9/site-packages/requests_toolbelt/_compat.py", line 56, in <module>
from requests.packages.urllib3.contrib.pyopenssl \
File "/usr/lib/pypy3.9/site-packages/urllib3/contrib/pyopenssl.py", line 82, in <module>
warnings.warn(
DeprecationWarning: 'urllib3.contrib.pyopenssl' module is deprecated and will be removed in a future release of urllib3 2.x. Read more
in this issue: https://github.com/urllib3/urllib3/issues/2680 |
In requests-toolbelt 0.10.1, the warning is only emitted for direct usage of |
Thanks a lot! I can confirm that we can successfully run the hypothesis test suite again now. |
See closed issue requests/toolbelt#331
urllib3 is in the process of deprecating urllib3.contrib.pyopenssl, see urllib3/urllib3#2680
requests-toolbelt currently attempts to import
from urllib3.contrib.pyopenssl import PyOpenSSLContext
. Apparently this is used byX509Adapter
.What's the path forward here? Can
X509Adapter
be ported to newer APIs that are supported?Otherwise it would be preferred if DeprecationWarning was only shown for code that actually uses
X509Adapter
, maybe make the import lazy and put it in a function?The text was updated successfully, but these errors were encountered: