Forcible response when Warning appears in Python's requests library

I often use the Python requests library because it's so convenient. It's annoying to get some warning at the time of execution.

For example, Insecure Platform Warning appears. I tried to deal with it by referring to this person, but it is troublesome to put in a package or downgrade.

So I decided to forcibly rewrite the source code.

Easy to rewrite.

In my case, I got this warning,

/usr/lib/python2.6/site-packages/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

Since the path of the source code is written carefully, open it with vim or something,

vim /usr/lib/python2.6/site-packages/requests/packages/urllib3/util/ssl_.py

It is OK if you comment out warnings.warn as follows

        def wrap_socket(self, socket, server_hostname=None, server_side=False):
            #warnings.warn(
            #    'A true SSLContext object is not available. This prevents '
            #    'urllib3 from configuring SSL appropriately and may cause '
            #    'certain SSL connections to fail. You can upgrade to a newer '
            #    'version of Python to solve this. For more information, see '
            #    'https://urllib3.readthedocs.io/en/latest/security.html'
            #    '#insecureplatformwarning.',
            #    InsecurePlatformWarning
            #)
            kwargs = {
                'keyfile': self.keyfile,
                'certfile': self.certfile,
                'ca_certs': self.ca_certs,
                'cert_reqs': self.verify_mode,
                'ssl_version': self.protocol,
                'server_side': server_side,
            }

This is enough! ?? w

Recommended Posts

Forcible response when Warning appears in Python's requests library
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
What to do when a warning appears around Python integration in Neovim's CheckHealth
What to do when "TypeError: data type not understood" appears in python's numpy.zeros
When codec can't decode byte appears in python
When Assertion `srcIndex <srcSelectDimSize` failed. Appears in TextGAN
Fix garbled characters when handling Japanese in Requests