pwitab / sos-access Goto Github PK
View Code? Open in Web Editor NEWPython client for sending alarm information via SOS Access V4.
Home Page: https://sos-access.readthedocs.io
License: BSD 3-Clause "New" or "Revised" License
Python client for sending alarm information via SOS Access V4.
Home Page: https://sos-access.readthedocs.io
License: BSD 3-Clause "New" or "Revised" License
response = client.send_alarm(
event_code='AL',
additional_info={'key': 'test'}
)
additional_info supports receiving a string, dict or an iterable (list, set, tuple). If dict it will be generated as a string with all keys and values on different rows. If an iterable it will be converted into a string with all items on different rows.
I tried sending an alarm similar to this. but at the receiving part (the alarm operator) say that they then don't receive the additional info line at all.
if I do this
response = client.send_alarm(
event_code='AL'
)
they receive in their system
additional_info=NAN
and doing this
response = client.send_alarm(
event_code='AL',
additional_info={'key = test'}
)
will "work" in the sense that they receive the string "key = test"
so i believe that the dict to string conversion dont work
Windows
python 3.8
Hi there,
I'm trying to test out the 'new authentication' flow and testing what happens for unsuccessful requests.
In these cases (e.g. incorrect old authentication), I would expect the newauthentication field in the response to be empty/omitted, but when I parse this as a response, it fails the NewAuthResponseSchema validation with an error like:
marshmallow.exceptions.ValidationError: {'newauthentication': ['Field may not be null.']}
This seems to be because this schema has the authentication marked as required. Is this correct? Do you have examples of an unsuccessful password change, does this just return the old password or something similar here?
FYI as well, in the documentation at https://sos-access.readthedocs.io/en/latest/sos_access_protocol.html#xml-examples-requestnewauthenticationresponse the sample is incorrect, as it shows the auth field as authentication
and not newauthentication
. When parsing the sample, I initially got tripped up as it returns an error like:
marshmallow.exceptions.ValidationError: {'newauthentication': ['Missing data for required field.'], 'authentication': ['Unknown field.']}
Thanks very much for your useful library + documentation as well, it's been very helpful in my testing.
I've created a REST API call from Thingsboard with the following included header:
Content-Type: application/json;charset=iso-8859-1 (tried with utf-8 as well)
Whenever any of the params for the sos-access contains swedish characters öäå, the lamda function raises this exception
(in this case for the letter å):
{
"errorMessage": "'latin-1' codec can't encode character '\\uffe5' in position 510: ordinal not in range(256)",
"errorType": "UnicodeEncodeError",
"stackTrace": [" File "/var/task/lambda_function.py", line 115, in lambda_handler\n AlarmResponse = client.send_alarm(\n", " File "/var/task/sos_access/client.py", line 176, in send_alarm\n return self._send_alarm(alarm_request)\n", " File "/var/task/sos_access/decorators.py", line 35, in retried_func\n result = func(*args, **kwargs)\n", " File "/var/task/sos_access/client.py", line 251, in _send_alarm\n alarm_response = self.transmit(\n", " File "/var/task/sos_access/client.py", line 367, in transmit\n transport.send(data.encode(self.ENCODING))\n"]
}
The maximum allowed telegram size in SOS Access v4 is 100 000 characters. Including XML headers.
As of now there is no check for this.
in client.py
def connect(self, address=None):
_address = address or self.address
self.socket.connect(_address)
_adress = 'alarm.example.com'
( i'm just trying to get the code to run at this point som i'm just using the example text)
and i receive
Exception has occurred: TypeError
getsockaddrarg: AF_INET address must be tuple, not str
File "C:\Users\nojonic\Documents\PYTHON\SOS Alarm Access v4\sos_access\client.py", line 424, in connect
self.socket.connect(_address)
File "C:\Users\nojonic\Documents\PYTHON\SOS Alarm Access v4\sos_access\client.py", line 300, in transmit
transport.connect()
...
I tried to simply do maket it a tuple with port number = 0, but then it fails somewhere else.
def connect(self, address=None):
_address = address or self.address
self.socket.connect((_address,0))
Exception has occurred: gaierror
[Errno 11001] getaddrinfo failed
I'm not sure if one is suppose to have an other socket.py or the code should accommodate tuple
OS : W10
python 3.6
pip 20.0.2
marshmallow 3.0.0b1
When using latest marshmallow 3.4.0, sending alarms or ping will stop the program
File "C:\Program Files\Python36\lib\site-packages\marshmallow\schema.py", line 1224, in _invoke_processors
data = processor(data, many=many, **kwargs)
TypeError: dump_xml() got an unexpected keyword argument 'many'
so i did a downgrade using
pip install "marshmallow==3.0.0b1"
and now it works better
root@raspberrypi:~# pip install sos-access
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting sos-access
Could not find a version that satisfies the requirement sos-access (from versi ons: )
No matching distribution found for sos-access
Forgot to remove some prints used for debugging.
Remove them and add logging so I can hook that up to the debug in Django where I'm using the lib in.
send-alarm:
Parameters:
event_code (str) – The event code of the alarm.
transmitter_time (str) – Time of the device or system sending the alarm reference (str) – A reference that will show up in logs on the alarm receiver.
it gives error if the tranmitter_time is not a datetime but a string like '2020-03-03 12.30:32.12345'
"'str' object has no attribute 'isoformat'"
The time on the alarm server used for testing is windows based and is sending times in local time (Sweden +2).
This could be an issue since python makes timezone unaware objects in local time if no timezone is given and if the client and server is in different timezones we will get differences in time.
Proposed solution is to add a custom Mashmallow field that can take an in timezone and and out timezone and transform the date to the correct timezone. Should also localize.
when i try to install with PIP i get an error message.
ERROR: Could not find a version that satisfies the requirement SOS-access ( from version: none)
ERROR: no matching distribution found for sos-access
i have python
-3.8-32
-3.7-64
-3.6-64
-3.5-64
-2.7-64
installed. all to PATH.
win10 machine
any idea what i could try to fix this?
Add a readthedocs page and start documentation
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.