Reputation: 505
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?
Upvotes: 6
Views: 3936
Reputation: 1340
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)
Upvotes: 3