This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Python Client Failed to establish a new connection

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.]

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

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

I mean how to setup API service ?

What setup do you want to do?

How to configure my API service to listen ?

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

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',))

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

Set api_url to https://ST2_IP/api

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

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

Thnx, finally I figured it out

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