AnsweredAssumed Answered

Problems writing to AF Attributes using PI Web API client library for Python (2017 R2)

Question asked by gavin.strack Champion on Jul 2, 2018
Latest reply on Jul 2, 2018 by gavin.strack

Hi PI^2,


I cannot write data to AF Attributes using the osisoft.pidevclub.piwebapi Python library. I can use all the various "read data" methods such as get_multiple_interpolated_values, etc. without any problems, so please ignore anything to do with API config or authentication.


I am trying to use the StreamAPI method using the following code:

def update_attribute_value(attribute_web_id, value):
    print("Web ID: %s" % attribute_web_id)
    print("Value: %s" % value), value)


I have confirmed that the correct arguments are being passed in, however I keep getting error 400 Bad Request.


Web ID: <removed for security reasons - but the correct string is here>
Value: 1
Traceback (most recent call last):
  File "", line 87, in <module>
    update_attribute_value(proposed_p_info.web_id, 1)
  File "", line 73, in update_attribute_value, value)
  File "C:\Users\pGavin.Strack\AppData\Local\Programs\Python\Python36-32\lib\site-packages\osisoft\pidevclub\piwebapi\api\", line 959, in update_value
    (data) = self.update_value_with_http_info(web_id, value, buffer_option, update_option, web_id_type, **kwargs)
  File "C:\Users\pGavin.Strack\AppData\Local\Programs\Python\Python36-32\lib\site-packages\osisoft\pidevclub\piwebapi\api\", line 1030, in update_value_with_http_info
    collection_formats =collection_formats)
  File "C:\Users\pGavin.Strack\AppData\Local\Programs\Python\Python36-32\lib\site-packages\osisoft\pidevclub\piwebapi\", line 311, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "C:\Users\pGavin.Strack\AppData\Local\Programs\Python\Python36-32\lib\site-packages\osisoft\pidevclub\piwebapi\", line 139, in __call_api
  File "C:\Users\pGavin.Strack\AppData\Local\Programs\Python\Python36-32\lib\site-packages\osisoft\pidevclub\piwebapi\", line 329, in request
  File "C:\Users\pGavin.Strack\AppData\Local\Programs\Python\Python36-32\lib\site-packages\osisoft\pidevclub\piwebapi\", line 77, in send_request
    raise ApiException(http_resp=response) (400)
Reason: Bad Request
HTTP response headers: {'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json', 'Server': 'Microsoft-HTTPAPI/2.0', 'X-Frame-Options': 'SAMEORIGIN', 'content-encoding': 'gzip', 'Date': 'Mon, 02 Jul 2018 04:08:06 GMT'}
HTTP response body: {"Errors":["An exception has occurred. Please contact your PI Web API administrator for help in enabling debug mode."]}


I am at a loss as to why this is not working, and would appreciate any assistance.