4 Replies Latest reply on Aug 30, 2017 10:03 AM by vinzenzeck

    PI Web API - 502 response and unconnected pi points

    vinzenzeck

      Hei,

       

      I am writing a data access tool to retrieve time series from the PI server for data analysis.

      Since, the data analysis is done with python, I decieded to use the PI Web API with the to communicate with the server.

       

      However the Pi Webapi seem to be broken from time to time.

      For example to retrieve an element by path I use the following url call:

       

      https://my_server.com/piwebapi/elements?path=%5Cmypath%5Cto%5Celement

       

      This returns an empty response if I don't do the following requests first:

       

      1. my_server.com/webapi

      2. https://my_server.com/piwebapi/assetservers

      3. search for the database in links of response and use the link for the last request: https://my_server.com/piwebapi/assetservers/JKASDKJBSD/assetdatabases

       

      some times this monkey patching works, sometimes it does not, resulting in an 502 gateway response for the 3. request.

      However when I then copy the request of 3. into the windows IE, I get a response. And the servers are set up.

      Then the python calls work as well.

       

      Furthermore, If I retreived the element and use this url for the attributes

       

      https://my_server.com/piwebapi/elements/LFNksE/attributes

       

      The attributes sometimes have a link to the PI Point and sometimes not. Which is crucial to receive any information.

      Here copy pasting the link into IE does not help fixing this problem

       

      What is going wrong?

        • Re: PI Web API - 502 response and unconnected pi points
          ashaw

          Hello vinzenz eck,

           

          For any type of issue where you are getting unexpected behaviors from the PI Web API, it would be important to know the response code.

          If the response is a 502 (bad gateway), then that typically indicates that the PI Web API got an invalid response from the upstream server (AF Server in this case).

           

          The first place I would look in such an instance is at the PI Web API Admin logs, and potentially even the debug/analytic logs.

          The Admin logs should record any un-handled exceptions or bad responses that the PI Web API service got from upstream resources.

          Let us know what you see in the logs and hopefully we'll have a better clue for how to move forward!

          • Re: PI Web API - 502 response and unconnected pi points
            vinzenzeck

            Hei Adam Shaw,

             

            Thanks for the fast answer. It took some time to get access to the server where the PI WebApi is installed.

             

            Admin logs:

            There are typically 3 errors raised each in its one log. Cronolocigal they state:

             

            1.

            System.ArgumentException: Invalid object path format for '\PI_DA\'.

            Parameter name: path

               at OSIsoft.AF.Support.AFPath.Parse(String path, AFObject relativeFrom, Nullable`1 queryDate, Boolean allowDynamic, Boolean returnFoundItems, AFIdentity preferredIdentity)

               at OSIsoft.AF.Support.AFPath.ParseIntoTokens(String path, AFObject relativeFrom, Boolean allowDynamic, AFIdentity preferredIdentity)

               at OSIsoft.REST.Controllers.ParallelRestorer.RestorePIPointByPath(String path)

               at OSIsoft.REST.Controllers.PointController.GetByPath(String path, String selectedFields)

               at lambda_method(Closure , Object , Object[] )

               at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)

               at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

            --- End

             

            2.

            System.ArgumentException: Requested value 'SELECT CommunicationId FROM' was not found.

               at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)

               at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)

               at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)

               at OSIsoft.AF.Support.AFPath.GetIdentity(Strig input)

               at OSIsoft.AF.Support.AFPath.ParseNameId(AFParsePathInfo parseInfo, Boolean inBrackets)

               at OSIsoft.AF.Support.AFPath.ParsePathPart(AFPath path, AFParsePathInfo parseInfo)

               at OSIsoft.AF.Support.AFPath.Parse(String path, AFObject relativeFrom, Nullable`1 queryDate, Boolean allowDynamic, Boolean returnFoundItems, AFIdentity preferredIdentity)

               at OSIsoft.AF.Support.AFPath.ParseIntoTokens(String path, AFObject relativeFrom, Boolean allowDynamic, AFIdentity preferredIdentity)

               at OSIsoft.REST.Controllers.Para

             

            3.

            System.ArgumentException: Requested value 'SELECT ID FROM' was not found.

               at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)

               at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)

               at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)

               at OSIsoft.AF.Support.AFPath.GetIdentity(String input)

               at OSIsoft.AF.Support.AFPath.ParseNameId(AFParsePathInfo parseInfo, Boolean inBrackets)

               at OSIsoft.AF.Support.AFPath.ParsePathPart(AFPath path, AFParsePathInfo parseInfo)

               at OSIsoft.AF.Support.AFPath.Parse(String path, AFObject relativeFrom, Nullable`1 queryDate, Boolean allowDynamic, Boolean returnFoundItems, AFIdentity preferredIdentity)

               at OSIsoft.AF.Support.AFPath.ParseIntoTokens(String path, AFObject relativeFrom, Boolean allowDynamic, AFIdentity preferredIdentity)

               at OSIsoft.REST.Controllers.ParallelRestorer.

             

             

            In the debug logs I found this:

             

            [Controllers]: Exception at getting PIPoint WebId. Cannot connect to the PI Data Archive.

            Windows authentication trial failed because insufficient privilege to access the PI Data Archive.

            Trust authentication trial failed because insufficient privilege to access the PI Data Archive.

             

             

            Best Vinzenz

              • Re: PI Web API - 502 response and unconnected pi points
                ashaw

                I can speak to issue 1 and the error in the debug logs:

                          System.ArgumentException: Invalid object path format for '\PI_DA\'.

                 

                This error indicates that the request provided an invalid path for a PI System resource.  I can almost exactly reproduce it by searching for a non-sense (this element does not exist) item on my PI System:

                https://webServer/piwebapi/elements?path=\pi_da\

                     "Errors": [

                       "Not found: '\\pi_da\\'. Invalid object path format for '\\pi_da\\'"

                       ]

                In such a case, I would investigate the application/client making the requests to ensure that it is passing valid paths - or that if it does pass an invalid path, that it can properly handle the 404 response from PI Web API.

                 

                The error from the debug logs indicates a problem with delegation to the PI Data Archive:

                     Windows authentication trial failed because insufficient privilege to access the PI Data Archive.

                     Trust authentication trial failed because insufficient privilege to access the PI Data Archive.

                 

                 

                The Admin Guide provides some guidance on how to troubleshoot Kerberos configuration issues, but there are basically 2 approaches:

                1. Configure PI Web API to use Basic Authentication, in which case Kerberos delegation is not required to communicate to the PI Data Archive (but this is less secure than option 2 and therefore not a recommended best-practice)
                2. Configure PI Web API to use Kerberos Authentication which will require the following to work properly as discussed in the admin guide:
                  1. HTTP Spns registered to the account running the PI Web API (if using the default virtual account, then this step is not necessary)
                  2. Service account running PI Web API is trusted for delegation, and is configured to delegate to the PI Data Archive (requires PIServer SPNs exist and are registered to PI Data Archive Machine, if service account is running as the default virtual account, then the machine needs to be configured to delegate to the PI Data Archive instead

                 

                Regarding the other 2 errors, I'm really not sure what is generating them, they appear to include SQL statements in the them (SELECT ID FROM...) which is confusing me.

                I think we'd need to take a closer look at what's happening (i.e. what specific requests are being made, and what the exact response body is for those requests).

              • Re: PI Web API - 502 response and unconnected pi points
                vinzenzeck

                Hei,

                 

                the responisible for the pi system in our company had similar connection problems, with data imports and PI system explorer.

                They resovled some errors related to an error The AF Link subsystem health status is: GenericBadState.

                This issue could be resolved with TechSupport.

                Now it seems that my data retrieving problems are solved as well.

                 

                Note to the issue 1:

                The occurence of the first issue is only temporary, sometimes the objcets in '\PI_DA' are there and sometimes not, depending on if the link between AF and Database is well established.

                Thus, this raises only a 502 and not a 404 response from the Web API.

                However this seems to be solved now (see above).