This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Python Module Httplib GET request issue

Hi all,

I found a related topic here and provided my 2 cents Rest Api Connection Failed‌‌, but I'm in need of an answer or advice so I thought I'd post my own question. I'm new to SolarWinds, and have found REST library for python/ mySQL queries. This can be found at :Plexxi/SolarWindsOrionREST · GitHub

In a nutshell, I'm attempting to query my organizations SolarWinds DB using this library but I'm running into some issues with my GET request. In swClassLib.py, the method sendRequest() is defined on line #88, and my request errors on line #115 after a failed HTTPConnection.Request() with an interestingly useless error message provided by the original developer.

I modified the Try/Except and discovered that the error is actually : [Errno 10054] An existing connection was forcibly closed by the remote host


Now I'm generally aware of what this error means, and I tried to catch it and re-establish my connection after waiting exponentially but to no avail.

I guess my question is, What is going wrong with this connection? If I try the same GET request from my browser, I'm greeted with the correct JSON object.

As a newbie, I'm quicker to put the blame on my implementation rather than blame a connection error on the server so any insight you could provide would be much appreciated!

Thanks

  • FormerMember
    0 FormerMember

    Is there an update to this?  Has anyone else seen this issue?  We upgraded our Solarwinds server, and now all our python scripts are busted.  We are receiving the same error:

    requests.exceptions.ConnectionError: ('Connection aborted.', error(10054, 'An existing connection was forcibly closed by the remote host'))

  • I've just gotten into working with the API in Python recently but I've not come across this with the versions of the modules I'm using. Maybe we can compare notes?

    (registernode)[sklassen@L1HDSandbox registernode]$ pip list

    boto3 (1.2.3)

    botocore (1.3.20)

    docutils (0.12)

    jmespath (0.9.0)

    pip (8.0.2)

    python-dateutil (2.4.2)

    requests (2.9.1)

    setuptools (18.2)

    six (1.10.0)

    swisclient (1.0.1)

    wheel (0.24.0)

    --

    Steven Klassen

    Developer Analyst @ Loop1 Systems, Inc.

    http://www.loop1systems.com/

  • Seems to be an error with httplib validating the SSL Cert on the server.

    to get a better error you can modify the code below,

    it seems to be a problem with httplib or at least the validation that its doing. most places will not have a valid cert or a cert signed internally.

    I'll have to play with the version of httplib i assume is now by default doing cert validation. likely an easy fix.

    '

    def sendRequest(self, **kwargs):

         --------------------snipped----------------

            try:

                conn.request(Type, URL, payload, self.header)

            except:

                print "Could not connect in call from %s. Unable to continue" % (caller)

                return None

    change to:

    def sendRequest(self, **kwargs):

        

        #    try:

         conn.request(Type, URL, payload, self.header)

            #except NameError:

            #    print "Could not connect in call from %s. Unable to continue" % (caller)

             #  return None

    '

    (prod)xxxxxxxx@xxxxxx:~/python/solarwinds$ python test.py

    Traceback (most recent call last):

      File "test.py", line 10, in <module>

        nodes1 = sw.getOrionNodes()

      File "/home/xxxxxxx/python/solarwinds/swClassLib.py", line 1717, in getOrionNodes

        status=200)

      File "/home/xxxxxxx/python/solarwinds/swClassLib.py", line 115, in sendRequest

        conn.request(Type, URL, payload, self.header)

      File "/usr/lib/python2.7/httplib.py", line 1001, in request

        self._send_request(method, url, body, headers)

      File "/usr/lib/python2.7/httplib.py", line 1035, in _send_request

        self.endheaders(body)

      File "/usr/lib/python2.7/httplib.py", line 997, in endheaders

        self._send_output(message_body)

      File "/usr/lib/python2.7/httplib.py", line 850, in _send_output

        self.send(msg)

      File "/usr/lib/python2.7/httplib.py", line 812, in send

        self.connect()

      File "/usr/lib/python2.7/httplib.py", line 1212, in connect

        server_hostname=server_hostname)

      File "/usr/lib/python2.7/ssl.py", line 350, in wrap_socket

        _context=self)

      File "/usr/lib/python2.7/ssl.py", line 566, in __init__

        self.do_handshake()

      File "/usr/lib/python2.7/ssl.py", line 788, in do_handshake

        self._sslobj.do_handshake()

    ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)

  • I was able to work around this by doing the following to swClassLib.py  I am certain there are better easier more elegant ways, but this is just what worked for me.

    swClassLib.py

    import ssl

    context = ssl._create_unverified_context()

    class SolarWinds():

    ----truncated----

    def https(self):

            httplib.HTTPSConnection.debuglevel = 0

            (change)

            return httplib.HTTPSConnection(self.ip, self.port)

             (TO:)

            return httplib.HTTPSConnection(self.ip, self.port, context=context)

  • FormerMember
    0 FormerMember in reply to loopback1

    The API HTTPS port uses the same self signed cert across all of the pollers in a installation. So it's not possible to do cert verification. I'm planning on raising a feature request so that Solarwinds make it possible.