集线器连接不是在Python中使用SignalR调用服务器的方法

问题描述 投票:0回答:1

我正在尝试建立集线器连接并通过证券交易所提供的API进行协商。这是使用Python中的Signalr_aio开发的代码。

from signalr_aio import Connection
import asyncio
from requests import Session

async def pushMessage(**msg):
    print(msg)
    if 'R' in msg and type(msg['R']) is not bool:
        token = msg['R']
        sessionRealtime.headers.update({'Authorization': 'Bearer {}'.format(token)})

server_url = 'https://edbi.ephoenix.ir/realtime'
sessionRealtime = Session()
connection = Connection(server_url, session=sessionRealtime)
connection.received += pushMessage
hub = connection.register_hub('omsclienttokenhub')
hub.server.invoke('GetAPIToken', 'xxxxxxxxx', 'yyyyyyyyyy')
hub = connection.register_hub('omsclienthub')
connection.start()

我尝试了'GetTime'方法,它确实成功返回了时间,

hub.server.invoke('GetTime')

{'R':'00:19:10','I':'2'}

但是,当我调用'GetInstrumentList'方法时出现错误,

hub.server.invoke('GetInstrumentList')

{'R':{'ex':{'i':无,'m':'对象引用未设置为实例的对象。'}},'I':'1'}

我想更新请求的标题有问题吗?还是应该在经过修改的URL中将令牌作为查询字符串传输?!

我正在尝试建立集线器连接并通过证券交易所提供的API进行协商。这是在Python中使用Signalr_aio开发的代码。来自signalr_aio ...

python python-requests signalr-hub
1个回答
1
投票

尝试以下代码

© www.soinside.com 2019 - 2024. All rights reserved.