Giter VIP home page Giter VIP logo

sos-access's People

Contributors

jonasnic avatar krolken avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jonasnic fperrin

sos-access's Issues

'latin-1' codec can't encode character

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"]
}

additional_info dict not converted to string

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

encoding

if there is a æ ø å in for example detector_text it will break with .invalid XML content

locally solved by reading the string to encoding UTF8 then decoding back to Latin1
shown in picture
detector will work
detector_text will not work in this pic

image

marshmallow 3.4.0

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

pip install sos-access

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?

Remove prints and logging

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.

tranmitter_time can't be string

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'"

New Authentication Response schema - newauthentication field

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.

Times from alarm server are without timezone.

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.

Address format question

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

No check for max telegram size.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.