Bloomberg blpapi in Python: "INVALID_USER"

59 Views Asked by At

I am trying to use blpapi connecting to remote bpipe application. Demo Tool works good for me.

Do i need some work on my session set up?

Env:python 3.9



def parseCmdLine():
    parser = OptionParser(description="Retrieve reference data.")
    parser.add_option("-a",
                      "--ip",
                      dest="host",
                      help="server name or IP (default: %default)",
                      metavar="ipAddress",
                      default="xxx.xx.xxx.xx")
    parser.add_option("-p",
                      dest="port",
                      type="int",
                      help="server port (default: %default)",
                      metavar="tcpPort",
                      default=xxxx)


    (options, args) = parser.parse_args()

    return options

def main():
    options = parseCmdLine()

    # Fill SessionOptions
    sessionOptions = blpapi.SessionOptions()
    sessionOptions.setServerHost(options.host)
    sessionOptions.setServerPort(options.port)
    sessionOptions.setAuthenticationOptions("AuthenticationMode=APPLICATION_ONLY;ApplicationAuthenticationType=APPNAME_AND_KEY;ApplicationName=app:key")
    print("Connecting to %s:%s" % (options.host, options.port))
    # Create a Session
    session = blpapi.Session(sessionOptions)

    # Start a Session
    if not session.start():
        print("Failed to start session.")
        return

    try:
        # Open service to get historical data from
        if not session.openService("//blp/refdata"):
            print("Failed to open //blp/refdata")
            return
        session.generateToken()
        # Obtain previously opened service
        refDataService = session.getService("//blp/refdata")

        # Create and fill the request for the historical data
        request = refDataService.createRequest("HistoricalDataRequest")
        request.getElement("securities").appendValue("IBM US Equity")
        request.getElement("securities").appendValue("MSFT US Equity")
        request.getElement("fields").appendValue("PX_LAST")
        request.getElement("fields").appendValue("OPEN")
        request.set("periodicityAdjustment", "ACTUAL")
        request.set("periodicitySelection", "MONTHLY")
        request.set("startDate", "20060101")
        request.set("endDate", "20061231")
        request.set("maxDataPoints", 100)

        print("Sending Request:", request)
        # Send the request
        session.sendRequest(request)

        # Process received events
        while(True):
            # We provide timeout to give the chance for Ctrl+C handling:
            ev = session.nextEvent(500)
            for msg in ev:
                print(msg)

            if ev.eventType() == blpapi.Event.RESPONSE:
                # Response completly received, so we could exit
                break
    finally:
        # Stop the session
        session.stop()

if __name__ == "__main__":
    print("SimpleHistoryExample")
    try:
        main()
    except KeyboardInterrupt:
        print("Ctrl+C pressed. Stopping...")

It replies with:


CID: {[ valueType=AUTOGEN classId=0 value=3 ]}
RequestId: 0c21a895-5bd5-449c-9296-86e1e8927933
HistoricalDataResponse = {
    responseError = {
        source = "rsfhdsvc2"
        code = 28
        category = "NO_AUTH"
        message = "Received error response from sescreate (service ID 343432) - Failed to load parmcm, due to a service error. Response=[ appCode = 1 message = "Failed to load parmcm asid 24756 asidSerial 118491 uuid 0 app 0 svc 0 flags 0: parmcmofflinethinpipe_managed_with_features: asid 24756 server mode (no identity(rc = 1217)(rc 1217)" isTransient = NULL ] [nid:44404] "
        subcategory = "INVALID_USER"
    }
}

Connection looks good, but still cannot get authorized. .............................................................................................................................................................

0

There are 0 best solutions below