我尝试使用此库连接到signalR api
https://pypi.org/project/signalr-client/
这是我的代码
from requests import Session
from signalr import Connection
with Session() as session:
#create a connection
connection = Connection("https://firouzex.exphoenixtrade.com/realtime", session)
#get chat hub
chat = connection.register_hub('GetNewAPIToken')
#start a connection
connection.start()
但我收到此错误
$ python test.py
Traceback (most recent call last):
File "test.py", line 12, in <module>
connection.start()
File "C:\Users\Rooz\AppData\Local\Programs\Python\Python35\lib\site-packages\signalr\_connection.py", line 47, in start
negotiate_data = self.__transport.negotiate()
File "C:\Users\Rooz\AppData\Local\Programs\Python\Python35\lib\site-packages\signalr\transports\_auto_transport.py", line 16, in negotiate
negotiate_data = Transport.negotiate(self)
File "C:\Users\Rooz\AppData\Local\Programs\Python\Python35\lib\site-packages\signalr\transports\_transport.py", line 28, in negotiate
negotiate.raise_for_status()
File "C:\Users\Rooz\AppData\Local\Programs\Python\Python35\lib\site-packages\requests\models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://firouzex.exphoenixtrade.com/realtime/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A+%22GetNewAPIToken%22%7D%5D
答案 0 :(得分:2)
我无法重现您的错误。该问题可能是由于软件包损坏或过时造成的,也许全新安装将解决您的问题。 SignalR
库依赖于这些软件包
certifi, idna, chardet, urllib3, requests, websocket-client, greenlet, pycparser, cffi, gevent, sseclient, signalr-client
要进行全新安装,请先卸载软件包
python -m pip uninstall -y certifi, idna, chardet, urllib3, requests, websocket-client, greenlet, pycparser, cffi, gevent, sseclient, signalr-client
然后重新安装
python -m pip install certifi, idna, chardet, urllib3, requests, websocket-client, greenlet, pycparser, cffi, gevent, sseclient, signalr-client --upgrade
答案 1 :(得分:0)
您应该使用omsclienttokenhub
而不是GetNewAPIToken
来注册中心。您还应该将signalr
更改为signalr_aio
。
欢呼。