2

When I try to make a request using:

request_arguments = {
    "method": method,
    "url": self._build_url(self.url, action),
    "headers": self._get_headers(**kwargs),
    "data": kwargs["data"] if "data" in kwargs else {},
    "verify": False
}

response = requests.request(**request_arguments)

I'm getting the following warning:

 tests/end_to_end/test_integration_alert.py::test_mm_put
      /anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py:858:
        InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised.
        See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
        InsecureRequestWarning)

I tried to suppress it in the constructor via:

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

as described here:

Suppress InsecureRequestWarning: Unverified HTTPS request is being made in Python2.6

Interestingly, I still get the warning the first time the code is called, but subsequent calls are correctly suppressed. (I hit the breakpoints in the correct order)

How can I suppress the initial warning as well?

martineau
  • 119,623
  • 25
  • 170
  • 301
James Hutchinson
  • 841
  • 2
  • 13
  • 27
  • You say subsequent requests are correctly suppressed, so it would be helpful to see your code. Python version would be helpful as well. – AlgoRythm Oct 28 '19 at 17:42
  • instead of `urllib3.disable_warnings()` you probably might need `import requests.package.urllib3 as urllib3` and then `urllib3.disable_warnings()` – Shan-Desai Oct 28 '19 at 18:00
  • @Shan-Desai no, `import requests.package.urllib3 as urllib3` is just a more complicated way to do `import urllib3` since requests >= 2.16.0, see https://github.com/psf/requests/blob/v2.22.0/requests/packages.py – Quentin Pradet Nov 14 '19 at 11:18

0 Answers0