Forum Discussion

Miguel_DeCamps's avatar
3 years ago

LM Python SDK add_device_property()


I'm running into an odd issue when using the LM SDK add_device_property() function. I have used this function many times but for some reason when I attempt to inject a custom property with an integer value for the custom property value I receive the following exception documented below. Even when I attempt to cast the value as a string before it's sent to the SDK somehow its not working and we still hit the same exception. If the value of the customproperty is an actual string with alpha characters then the custom property is created without issue using the add_device_property function. Am I doing something wrong or is there possibly a bug in the SDK? I will also add that when we ADD a new device using the SDK and provide a custom property with an integer value it works and adds the custom property without issue. 

Examples of the custom prop payload:

{'name': 'autotask.accountnumber', 'value': 1234567} <-- this gives us the exception below

{'name': 'autotask.accountnumber', 'value': '1234567'} <-- this gives also gives us the exception below you can see the value is sent as a string

{'name': 'autotask.accountnumber', 'value': '_1234567'} <-- when we send the value as shown to the left it works without issue (but we dont want this value it needs to be a number)

Traceback (most recent call last):
File "Python Workspace\Logicmonitor Add\", line 47, in <module>
api_response = api_instance.add_device_property(devid,custprop)
File "Python Workspace\Logicmonitor Add\env\lib\site-packages\logicmonitor_sdk\api\", line 1966, in add_device_property
(data) = self.add_device_property_with_http_info(device_id, body, **kwargs) # noqa: E501
File "Python Workspace\Logicmonitor Add\env\lib\site-packages\logicmonitor_sdk\api\", line 2046, in add_device_property_with_http_info
return self.api_client.call_api(
File "Python Workspace\Logicmonitor Add\env\lib\site-packages\logicmonitor_sdk\", line 331, in call_api
return self.__call_api(resource_path, method,
File "Python Workspace\Logicmonitor Add\env\lib\site-packages\logicmonitor_sdk\", line 122, in __call_api
path_params = self.sanitize_for_serialization(path_params)
File "Python Workspace\Logicmonitor Add\env\lib\site-packages\logicmonitor_sdk\", line 224, in sanitize_for_serialization
return {key: self.sanitize_for_serialization(val)
File "Python Workspace\Logicmonitor Add\env\lib\site-packages\logicmonitor_sdk\", line 224, in <dictcomp>
return {key: self.sanitize_for_serialization(val)
File "Python Workspace\Logicmonitor Add\env\lib\site-packages\logicmonitor_sdk\", line 221, in sanitize_for_serialization
for attr, _ in six.iteritems(obj.swagger_types)
AttributeError: 'numpy.int64' object has no attribute 'swagger_types'

2 Replies

  • Hi Stewart,

    We seem to have found the issue thanks to your help. We took your example and added it exactly as you had typed and it worked we then worked backwards and found the problem to be how Pandas handles the CSV data that is read in. We had previously casted the value of the custom property but never looked at the deviceId property which was also being returned as a Numpy.Int64 value. We were able to fix the problem on the Pandas function that we use to read the CSV and leveraged the dtype parameter to ensure that the datatype did not end up as a Numpy.Int64 type.

    mydata = pd.read_csv("accounts.csv", skiprows=1, names=['deviceId', 'autotask.accountnumber'], dtype={'deviceId': int,'autotask.accountnumber':str})

  • Anonymous's avatar

    That's odd. I was able to execute the following:



    And got this response:

    {'inherit_list': [],
     'name': 'mycustomprop',
     'type': 'custom',
     'value': '123456789'}


    I went and checked that device and the custom property is there.

    Perhaps if we could see more of your script (be sure to sanitize of api keys/tokens).