ChristianTremblay / pyhaystack

Pyhaystack is a module that allow python programs to connect to a haystack server project-haystack.org. Connection can be established with Niagara Platform running the nhaystack, Skyspark and Widesky. For this to work with Anaconda IPython Notebook in Windows, be sure to use "python setup.py install" using the Anaconda Command Prompt in Windows. If not, module will be installed for System path python but won't work in the environment of Anaconda IPython Notebook. You will need hszinc 1.3+ for this to work.
Apache License 2.0
73 stars 31 forks source link

Possible error while fetching data from a Niagara server hosted on HTTPS #114

Closed krishabh-95 closed 1 year ago

krishabh-95 commented 1 year ago

Hi,

I am trying to connect to a few Niagara 4 instances using pyhaystack. When I try to connect to the instances hosted on http, it works fine but when I try to connect to a Niagara4 instance hosted on https, it throws an error. I am using the following code to establish a connection:

from pyhaystack.client.niagara import Niagara4HaystackSession session = Niagara4HaystackSession(uri=niagara_host, username=niagara_user, password=niagara_password)

Should I do something different to connect to a https instance of Niagara4? Just so you know, haystack service has been enabled in this instance since I am able to fetch the data when I execute the URL niagara-host/haystack/about in the browser. Thanks in advance.

sjlongland commented 1 year ago

You mention it "throws an error" but don't say which one… I'm guessing possibly a certificate error?

There are a couple of ways around this:

  1. disabling TLS verification altogether (not the wisest idea, but can work): specify http_args=dict(tls_verify=False) in the session constructor arguments (along side the uri)
  2. obtain a copy of the certificate from the remote server, and specify the path to that file; http_args=dict(tls_verify="/path/to/remote.crt") in the session constructor arguments.
krishabh-95 commented 1 year ago

Sorry I forgot to mention the exact error. Yes, it was a certificate error indeed. It works fine now after disabling TLS verification. Thanks a lot for your help.

I'll try to get a copy of the certificate from the remote server and use it for TLS verification.