How can we connect to PI Achieve database with Python(step by Step procedure).

PI server is in VM -A

PI AF server and PI SQL DAS server is in VM-B

and Python is installed in VM-C

 

all three VM's are in Same domain.

I am able to ping VM-B form VM-C

I want data of PI AF( tags , its history) , in Python installed in VM-C.

 

How can we do that.

 

Please suggest possible steps.

Parents Reply Children
  • I'm interested to go with requests and had issues with SSL cert initially(which is resolved after using the internal CA).

     

    PI-Webapi is configured as Kerberos authentication and wanted to connect to PI DA via PI-WebAPI using sample example below.

     

    import requests

    from requests_kerberos import HTTPKerberosAuth

     

    # Set up the base URL of the Pi Web API

    base_url = "https://piwebapi/"

     

    # Set up the HTTPKerberosAuth authentication

    auth = HTTPKerberosAuth()

     

    # Construct the full URL

    url = f"PIwebapi/points?path=\\PIserver\PITag"

     

    # Send the GET request with Kerberos authentication

    response = requests.get(url, auth=auth)

     

    # Check if the request was successful

    if response.status_code == 200:

      data = response.json()

      value = data["Value"]

      print(f"Value of {attribute_name}: {value}")

    else:

      print(f"Request failed with status code: {response.status_code}")

     

    In Output, I'm getting following error result.

    Traceback (most recent call last):

     File "C:\Program Files\Python311\Lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request

      self._validate_conn(conn)

     File "C:\Program Files\Python311\Lib\site-packages\urllib3\connectionpool.py", line 1092, in _validate_conn

      conn.connect()

     File "C:\Program Files\Python311\Lib\site-packages\urllib3\connection.py", line 635, in connect

      sock_and_verified = _ssl_wrap_socket_and_match_hostname(

     File "C:\Program Files\Python311\Lib\site-packages\urllib3\connection.py", line 776, in _ssl_wrap_socket_and_match_hostname

  • Hi ​,

    There are some popular Python packages, such as pyodbc, requests, and pythonnet, that can be used to use with PI Drivers. But I'd say the priority should come from you and your business needs.

  • Hi ​,

    I noticed 2 things from your code:

    • Please verify your url by printing it. Your url should be base_url + url.
    • HTTPKerberosAuth authentication by default seems to require Mutual_authentication. piwebapi only requires the clients to accept the server one and not the other way around. Please try setting this to Optional.