AnsweredAssumed Answered

Python through PI WebAPI

Question asked by Geert@Pi on Mar 1, 2019
Latest reply on Jul 2, 2020 by jagdish.konathala

Hi guys, I having an SSL issue. I'm trying to connect to PI through Python using PI WebAPI.

 

I've found this library on GitHub: GitHub - aabrodskiy/PI-Web-API-Client-Python

But when I try:

from osisoft.pidevclub.piwebapi.pi_web_api_client import PIWebApiClient

client = PIWebApiClient("https://PISERV1.domain/piwebapi", useKerberos=True, verifySsl=True)

df1 = client.data.get_recorded_values("pi:\\\\PISERV1\\SINUSOIDU", start_time="*-1d", end_time="*")

I get this:

    Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\packages\urllib3\contrib\pyopenssl.py", line 417, in wrap_socket

    cnx.do_handshake()

  File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1426, in do_handshake

    self._raise_ssl_error(self._ssl, result)

  File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1174, in _raise_ssl_error

    _raise_current_error()

  File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\_util.py", line 48, in exception_from_error_queue

    raise exception_type(errors)

OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')]

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 594, in urlopen

    chunked=chunked)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 350, in _make_request

    self._validate_conn(conn)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 835, in _validate_conn

    conn.connect()

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\packages\urllib3\connection.py", line 323, in connect

    ssl_context=context)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 324, in ssl_wrap_socket

    return context.wrap_socket(sock, server_hostname=server_hostname)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\packages\urllib3\contrib\pyopenssl.py", line 424, in wrap_socket

    raise ssl.SSLError('bad handshake: %r' % e)

ssl.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 423, in send

    timeout=timeout

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 624, in urlopen

    raise SSLError(e)

requests.packages.urllib3.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File ".\hipi.py", line 24, in <module>

    df1 = client.data.get_recorded_values("pi:\\\\PISERV1\\SINUSOIDU", start_time="*-1d", end_time="*")

  File "C:\ProgramData\Anaconda3\lib\site-packages\osisoft.pidevclub.piwebapi-1.11.1-py3.6.egg\osisoft\pidevclub\piwebapi\api\data_api.py", line 261, in get_recorded_values

  File "C:\ProgramData\Anaconda3\lib\site-packages\osisoft.pidevclub.piwebapi-1.11.1-py3.6.egg\osisoft\pidevclub\piwebapi\api\data_api.py", line 36, in convert_path_to_web_id

  File "C:\ProgramData\Anaconda3\lib\site-packages\osisoft.pidevclub.piwebapi-1.11.1-py3.6.egg\osisoft\pidevclub\piwebapi\api\point_api.py", line 29, in get_by_path

  File "C:\ProgramData\Anaconda3\lib\site-packages\osisoft.pidevclub.piwebapi-1.11.1-py3.6.egg\osisoft\pidevclub\piwebapi\api\point_api.py", line 93, in get_by_path_with_http_info

  File "C:\ProgramData\Anaconda3\lib\site-packages\osisoft.pidevclub.piwebapi-1.11.1-py3.6.egg\osisoft\pidevclub\piwebapi\api_client.py", line 311, in call_api

  File "C:\ProgramData\Anaconda3\lib\site-packages\osisoft.pidevclub.piwebapi-1.11.1-py3.6.egg\osisoft\pidevclub\piwebapi\api_client.py", line 139, in __call_api

  File "C:\ProgramData\Anaconda3\lib\site-packages\osisoft.pidevclub.piwebapi-1.11.1-py3.6.egg\osisoft\pidevclub\piwebapi\api_client.py", line 329, in request

  File "C:\ProgramData\Anaconda3\lib\site-packages\osisoft.pidevclub.piwebapi-1.11.1-py3.6.egg\osisoft\pidevclub\piwebapi\rest.py", line 57, in send_request

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 70, in get

    return request('get', url, params=params, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\api.py", line 56, in request

    return session.request(method=method, url=url, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 488, in request

    resp = self.send(prep, **send_kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 609, in send

    r = adapter.send(request, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 497, in send

    raise SSLError(e, request=request)

requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

 

I am using Kerberos as authentication method and I have a valid server certificate. (It works fine for PI Vision and PI Webapi through a browser). Am I missing something here?

 

Kind regards,

Geert

Outcomes