使用asyncio的高速公路 - 无法使用路径为URL创建连接

时间:2017-03-22 09:40:53

标签: python-3.x python-asyncio autobahn

我正在尝试连接到两个WebSockets(带有URI wss://domainA.com的WebSocket A和带有URI wss://domainB.com/path的WebSocket B),使用在asyncio上运行的Autobahn,如{{3 }}。

我已经像这样创建了一个WebSocketClientProtocol:

from autobahn.asyncio.websocket import WebSocketClientProtocol

class ClientProtocol(WebSocketClientProtocol):
    def onConnect(self, response):
        print("Connected to Server: {}".format(response.peer))

并使用asyncio连接连接到WebSocket:

from autobahn.asyncio.websocket import WebSocketClientFactory
import asyncio

factory = WebSocketClientFactory()
factory.protocol = ClientProtocol

loop = asyncio.get_event_loop()

coro = loop.create_connection(factory, 'domainA.com', 80)

loop.run_until_complete(coro)
loop.run_forever()
loop.close()

我能够连接到WebSocket A,但用domainA.com替换domainB.com/path连接到WebSocket B会导致错误gaierror: [Errno 8] nodename nor servname provided, or not known.

我知道WebSocket B正在工作,因为我可以使用不同的库连接到它。此外,仅使用domainB.com/path替换domainB.com会导致connection was closed uncleanly (WebSocket connection upgrade failed (301 - MovedPermanently))

0 个答案:

没有答案