I’ve installed the API helper functions provided by the weather station I’m trying to connect to. I did this using ‘pip install ambient_api==1.5.1’ and creating a symlink from …/ignition/user-lib/pylib/site-packages to the jython install folder’s site-packages.
First problem:
when I try to test code using igniton’s script console, it seems to be using a local cache copy of everything, well almost everything. I don’t think it brings over a copy of the environment variables needed and maybe more, so I get errors related to that— so next I tried to create a button in perspective, with a script–
Second problem:
within the perspective button script, I have:
from ambient_api.ambientapi import AmbientAPI
import time
api = AmbientAPI()
devices = api.get_devices()
device = devices[0]
time.sleep(1) #pause for a second to avoid API limits
print(device.get_data())
when I click the button, I get the following errors
com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "<function:runAction>", line 2, in runAction
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/ambient_api/ambientapi.py", line 4, in <module>
import requests
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/requests/__init__.py", line 120, in <module>
from . import utils
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/requests/utils.py", line 27, in <module>
from ._internal_utils import to_native_string
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/requests/_internal_utils.py", line 11, in <module>
from .compat import is_py2, builtin_str, str
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/requests/compat.py", line 31, in <module>
import json
File "/usr/local/bin/ignition/user-lib/pylib/json/__init__.py", line 108, in <module>
from .decoder import JSONDecoder
File "/usr/local/bin/ignition/user-lib/pylib/json/decoder.py", line 24, in <module>
NaN, PosInf, NegInf = _floatconstants()
File "/usr/local/bin/ignition/user-lib/pylib/json/decoder.py", line 18, in _floatconstants
_BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
File "user-lib/pylib/encodings/__init__.py", line 142, in search_function
raise CodecRegistryError,\
encodings.CodecRegistryError: incompatible codecs in module "encodings.hex_codec" (/usr/local/bin/ignition/user-lib/pylib/encodings/hex_codec.py)
caused by org.python.core.PyException
Traceback (most recent call last):
File "<function:runAction>", line 2, in runAction
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/ambient_api/ambientapi.py", line 4, in <module>
import requests
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/requests/__init__.py", line 120, in <module>
from . import utils
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/requests/utils.py", line 27, in <module>
from ._internal_utils import to_native_string
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/requests/_internal_utils.py", line 11, in <module>
from .compat import is_py2, builtin_str, str
File "/usr/local/bin/ignition/user-lib/pylib/site-packages/requests/compat.py", line 31, in <module>
import json
File "/usr/local/bin/ignition/user-lib/pylib/json/__init__.py", line 108, in <module>
from .decoder import JSONDecoder
File "/usr/local/bin/ignition/user-lib/pylib/json/decoder.py", line 24, in <module>
NaN, PosInf, NegInf = _floatconstants()
File "/usr/local/bin/ignition/user-lib/pylib/json/decoder.py", line 18, in _floatconstants
_BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
File "user-lib/pylib/encodings/__init__.py", line 142, in search_function
raise CodecRegistryError,\
encodings.CodecRegistryError: incompatible codecs in module "encodings.hex_codec" (/usr/local/bin/ignition/user-lib/pylib/encodings/hex_codec.py)
Ignition v8.1.0 (b2020110211)
Java: Azul Systems, Inc. 11.0.7
I don’t understand what this is telling me. Can anyone help me through it?