question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot suppress urllib3 warnings

See original GitHub issue

Library:

  • pywinrm==0.3.0
  • requests==2.22.0
  • urllib3==1.25.3

Issues: urllib3.exceptions.HeaderParsingError isn’t suppressed

Python Code:

import logging
import winrm
logging.basicConfig(level=logging.DEBUG)
session = winrm.Session(remote, auth=(username, password), transport="ntlm", server_cert_validation="ignore")
result = session.run_cmd('ipconfig', ['/all'])
logging.info(result.std_out.decode())

Trace:

DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): nangs-jw1.eng.citrite.net:5985
DEBUG:urllib3.connectionpool:http://nangs-jw1.eng.citrite.net:5985 "POST /wsman HTTP/1.1" 401 0
DEBUG:urllib3.connectionpool:Resetting dropped connection: nangs-jw1.eng.citrite.net
DEBUG:urllib3.connectionpool:http://nangs-jw1.eng.citrite.net:5985 "POST /wsman HTTP/1.1" 401 0
DEBUG:urllib3.connectionpool:http://nangs-jw1.eng.citrite.net:5985 "POST /wsman HTTP/1.1" 200 0
DEBUG:urllib3.connectionpool:http://nangs-jw1.eng.citrite.net:5985 "POST /wsman HTTP/1.1" 200 1896
WARNING:urllib3.connectionpool:Failed to parse headers (url=http://nangs-jw1.eng.citrite.net:5985/wsman): [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''
Traceback (most recent call last):
  File "/home/administrator/.pyenv/versions/3.7.4/lib/python3.7/site-packages/urllib3/connectionpool.py", line 399, in _make_request
    assert_header_parsing(httplib_response.msg)
  File "/home/administrator/.pyenv/versions/3.7.4/lib/python3.7/site-packages/urllib3/util/response.py", line 72, in assert_header_parsing
    raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data)
urllib3.exceptions.HeaderParsingError: [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()], unparsed data: ''

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13

github_iconTop GitHub Comments

3reactions
benjamin-heimann-dbcommented, Aug 26, 2021

In urllib3==1.25.11 this issue exists, while in the newest version urllib3==1.26.6 it is fixed for me.

1reaction
badcurecommented, Aug 16, 2019

Script used: httplib_response_testing.py

Going through that script(I wanted to be 100% sure), it does look like an issue upstream. Testing the output from an encrypted and non-encrypted server displays the following:

p[brian.price@localhost pywinrm]$ python3 httplib_testing.py 
Headers
Content-Type: multipart/encrypted;protocol="application/HTTP-SPNEGO-session-encrypted";boundary="Encrypted Boundary"
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 16 Aug 2019 19:28:01 GMT
Content-Length: 1895


Defects
[StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()]
Unencrypted
Headers
Content-Type: application/soap+xml;charset=UTF-8
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 16 Aug 2019 19:32:37 GMT
Content-Length: 1637


Defects
[]

After some debugging, the errors are not really a problem IMO. When http_client.HTTPResponse passes on the header only for processing toemail.parser.Parser here , those errors are generated because it believes it is processing an entire response.

The parsestr allows to specify that it is headers only, and not attempt to process any body. The definition is here

I think suppressing these errors may be the best course of action for now…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unverified HTTPS request is being made in Python2.6 - Stack ...
To disable warnings in requests' vendored urllib3, you'll need to import that ... This will suppress all warnings though, not just InsecureRequest (ie...
Read more >
Suppress SSL certificate warnings when ssl_verify=False is set?
I'm using influxdb-python with an InfluxDB instance with a self-signed SSL certificate. I have ssl=True, and ssl_verify=False is on by default (although I ......
Read more >
How to disable InsecureRequestWarning: Unverified HTTPS ...
How to disable InsecureRequestWarning: Unverified HTTPS request is being made. If you use requests or urllib3, requests with SSL ...
Read more >
unverified https request is being made to host - You.com | The ...
To disable warnings in requests' vendored urllib3, you'll need to import that ... InfluxDB cannot connect From Remote host using Python client Script....
Read more >
Advanced Usage - urllib3 1.26.13 documentation
Finally, you can suppress the warnings at the interpreter level by setting the PYTHONWARNINGS environment variable or by using the -W flag. Google...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found