8 Replies Latest reply on Jul 2, 2018 5:26 AM by gavin.strack

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


      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)
          client.stream.update_value(attribute_web_id, 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 "test.py", line 87, in <module>
          update_attribute_value(proposed_p_info.web_id, 1)
        File "test.py", line 73, in update_attribute_value
          client.stream.update_value(attribute_web_id, value)
        File "C:\Users\pGavin.Strack\AppData\Local\Programs\Python\Python36-32\lib\site-packages\osisoft\pidevclub\piwebapi\api\stream_api.py", 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\stream_api.py", 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\api_client.py", 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\api_client.py", line 139, in __call_api
        File "C:\Users\pGavin.Strack\AppData\Local\Programs\Python\Python36-32\lib\site-packages\osisoft\pidevclub\piwebapi\api_client.py", line 329, in request
        File "C:\Users\pGavin.Strack\AppData\Local\Programs\Python\Python36-32\lib\site-packages\osisoft\pidevclub\piwebapi\rest.py", line 77, in send_request
          raise ApiException(http_resp=response)
      osisoft.pidevclub.piwebapi.rest.ApiException: (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.