首页 > 解决方案 > Google Colab 中的 blpapi 抛出 InvalidArgumentException

问题描述

试图在 Google Colab 环境中运行一个非常普通的 BDP。任何人都可以解决这个问题?

安装依赖项:

!pip install --index-url=https://bcms.bloomberg.com/pip/simple/blpapi

开始我的会议:

import blpapi
session = blpapi.Session()
session.start()


session.openService("//blp/refdata")

service = session.getService("//blp/refdata")
request = service.createRequest("ReferenceDataRequest")

request.append("securities", "USDCAD Curncy")
request.append("fields", "PX_OPEN")

session.sendRequest(request)

endReached = False

while endReached == False:
    ev = session.nextEvent()
    if ev.eventType() == blpapi.Event.RESPONSE or ev.eventType() == blpapi.Event.PARTIAL_RESPONSE:
        for msg in ev:
                
            print (msg)
    if ev.eventType() == blpapi.Event.RESPONSE:
        endReached = True

这给了我一个:

    ---------------------------------------------------------------------------
InvalidArgumentException                  Traceback (most recent call last)
<ipython-input-10-5882776bd4df> in <module>()
      7 
      8 service = session.getService("//blp/refdata")
----> 9 request = service.createRequest("ReferenceDataRequest")
     10 
     11 request.append("securities", "USDCAD Curncy")

2 frames
/usr/local/lib/python3.7/dist-packages/blpapi/service.py in createRequest(self, operation)
    381             self.__handle,
    382             operation)
--> 383         _ExceptionUtil.raiseOnError(errCode)
    384         return Request(request, self.__sessions)
    385 

/usr/local/lib/python3.7/dist-packages/blpapi/exception.py in raiseOnError(errorCode, description)
    144         """
    145         if errorCode:
--> 146             _ExceptionUtil.raiseException(errorCode, description)
    147 
    148 __copyright__ = """

/usr/local/lib/python3.7/dist-packages/blpapi/exception.py in raiseException(errorCode, description)
    136                 description = "Unknown"
    137         errorClass = _ExceptionUtil.__getErrorClass(errorCode)
--> 138         raise errorClass(description, errorCode)
    139 
    140     @staticmethod

InvalidArgumentException: Null service handle (0x00020002)

任何指针表示赞赏。谢谢

标签: pythongoogle-colaboratorybloomberg

解决方案


推荐阅读