readTest.py issues

I was trying to use the openHistorian API to read some data and output it to the terminal. I copied the readTest.py from the GitHub and I ran into a couple errors.

D:\DCS\Scripts>python readTest.py
Connecting to openHistorian…
Opening “PPA” database instance…
Requesting metadata from openHistorian…
Received 1,396,137 bytes of metadata in 1.34 seconds. Decompressing…
Decompressed 11,396,927 bytes of metadata in 0.34 seconds. Parsing…
Parsed 23,495 metadata records in 0.81 seconds.
Discovered:
20,978 measurement records
347 device records, and
2,170 phasor records
Queried 21 metadata records associated with “PPA” database instance.
D:\DCS\Scripts\readTest.py:73: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in
** a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).**
** endTime = datetime.utcnow() - timedelta(seconds = 10)**
Starting read for 21 points from 2024-11-06 21:21:51.273281 to 2024-11-06 21:21:51.306281…

Failed to connect: unsupported type for timedelta microseconds component: numpy.uint64
Traceback (most recent call last):
File “D:\DCS\Scripts\readTest.py”, line 108, in
readTest()
~~~~~~~~^^
File “D:\DCS\Scripts\readTest.py”, line 83, in readTest
instance.Dispose()
~~~~~~~~~~~~~~~~^^
File “C:\Users\jmcmanus\AppData\Roaming\Python\Python313\site-packages\snapDB\snapClientDatabase.py”, line 220, in Dis
pose
Server.ValidateExpectedReadResponse(self.stream, ServerResponse.DATABASEDISCONNECTED)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\jmcmanus\AppData\Roaming\Python\Python313\site-packages\snapDB_init_.py”, line 60, in ValidateExpect
edReadResponse
Server.ValidateExpectedResponse(Server.ReadResponse(stream), expectedResponse)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\jmcmanus\AppData\Roaming\Python\Python313\site-packages\snapDB_init_.py”, line 44, in ValidateExpect
edResponse
raise RuntimeError(f"Unexpected server response: {response}")
RuntimeError: Unexpected server response: 128

Is this still the most up to date example of using the API to read?

Hi Jacob!

Looks like you are using the latest Python, v3.13, perhaps there may be some compatibility issues with this newer version, we will need to look at that. FYI, I know the code works with Python v3.9 on which it was developed.

I’ll check out your issue ASAP.

Thanks,
Ritchie

Hello,
I had to use the datetime object in a Python 3.12 project and used datetime.datetime.now(datetime.timezone.utc) because .utcnow() is deprecated in this version. This new approach is more accurate than utcnow() because it also returns the timezone. Maybe trying to replace datetime.datetime.utcnow() by datetime.datetime.now(). Both objects return a datetime ; but the second ad the timezone as follow :

  • datetime.utcnow() returns : 2024-11-27 14:30:45.123456
  • datetime.now() returns : 2024-11-27 14:30:45.123456+00:00

Note that datetime.now().replace(tzinfo=None) returns the same thing as datetime.utcnow()

Hope this help,

Regards
Stephane.

1 Like