Disable HeaderParsingError appearing from python3 urllib3
Asked Answered
N

1

6

how can I suppress the Failed to parse headers error that appears from the urllib3 library?

The following errors keep appearing:

Failed to parse headers (url=https://test): [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''
Traceback (most recent call last):
  File "/opt/test_project/.venv/lib/python3.5/site-packages/urllib3/connectionpool.py", line 399, in _make_request
    assert_header_parsing(httplib_response.msg)
  File "/opt/test_project/.venv/lib/python3.5/site-packages/urllib3/util/response.py", line 66, in assert_header_parsing
    raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
urllib3.exceptions.HeaderParsingError: [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''

I have tried to suppress it using

import urllib3
# Disable SSL warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Disbale urllib3.exceptions.HeaderParsingError:
urllib3.disable_warnings(urllib3.exceptions.HeaderParsingError)

but seems like it's not working as it is still appearing.

There are some solutions online but that is suppressing via the logs. I am looking for a method to suppress it not from the log level.

AFAIK, this is just the warning from urllib3 and it's been reported as a bug. Therefore, is there any way I can suppress this?

Nonbelligerent answered 26/6, 2019 at 23:8 Comment(0)
P
3


Suppress logs using standard python library 'logging'


Place this code on the top of your existing code to ignore logs from urllib3 package

import logging
urllib3_logger = logging.getLogger('urllib3')
urllib3_logger.setLevel(logging.CRITICAL)
Paigepaik answered 13/1, 2021 at 16:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.