Python Client Failed to establish a new connection

api
python
st2client

(Irek Romaniuk) #1

I am trying to use python client to connect

>>> from st2client.client import Client
>>> from st2client import models
>>> client = Client(base_url='http://10.29.95.102')
>>> rules = client.rules.get_all()

but after last command getting error below ?

requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.29.95.102', port=9101): Max retries exceeded with url: /v1/rules (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f34b197a4d0>: Failed to establish a new connection: [Errno 111] Connection refused',))

On server I can see this is reset :slight_smile:

IP 10.29.95.102.9101 > 10.199.107.14.51032: Flags [R.]

(Lindsay Hill) #2

So…have you configured your API service to listen on that port on that IP?

RST flag means the port is closed, so I’m guessing the answer is “no”.

You almost certainly don’t want to connect to the API service using http. You almost certainly want to go via https://<your_IP>/api


(Irek Romaniuk) #3

Will you send me to the doc ? I mean how to setup API service ?


(Lindsay Hill) #4

I mean how to setup API service ?

What setup do you want to do?


(Irek Romaniuk) #5

How to configure my API service to listen ?


(Lindsay Hill) #6

You almost certainly don’t want to connect to the API service using http. You almost certainly want to go via https://<your_IP>/api


(Irek Romaniuk) #7

But when I try client = Client(base_url=‘https://10.29.95.102’) then getting same error

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='10.29.95.102', port=9101): Max retries exceeded with url: /v1/rules (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f34b19e3890>: Failed to establish a new connection: [Errno 111] Connection refused',))

(Irek Romaniuk) #8

sorry , better now but new error

>>> client = Client(base_url='https://10.29.95.102/api')
>>> rules = client.rules.get_all()
/usr/local/lib/python2.7/dist-packages/requests-2.14.2-py2.7.egg/requests/packages/urllib3/connectionpool.py:852: 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)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "st2client/models/core.py", line 40, in decorate
    return func(*args, **kwargs)
  File "st2client/models/core.py", line 193, in get_all
    self.handle_error(response)
  File "st2client/models/core.py", line 166, in handle_error
    response.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests-2.14.2-py2.7.egg/requests/models.py", line 928, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found
Unable to retrieve detailed message from the HTTP response. No JSON object could be decoded
 for url: https://10.29.95.102/api:9101/v1/rules

(Lindsay Hill) #9

Set api_url to https://ST2_IP/api


(Lindsay Hill) #10

Check st2/st2client at master · StackStorm/st2 · GitHub


(Irek Romaniuk) #11

Yeah, my example is from that url . Where do I put token ?

requests.exceptions.HTTPError: 401 Client Error: Unauthorized
MESSAGE: Unauthorized - One of Token or API key required. for url: https://10.29.95.102/api/rules

(Irek Romaniuk) #12

Thnx, finally I figured it out

client = Client(api_url='https://10.29.95.102/api',token="xxxx")