Hasura:订阅不支持子目录

2024-09-27 23:16:51 发布

您现在位置:Python中文网/ 问答频道 /正文

subscription = Template('''
    subscription {
        users {
            id
            name
        }
    }
''')

async def user_listener():

    headers = {'Content-Type': 'application/json',
               'x-hasura-access-key': 'mysecretkey'}

    uri = "ws://localhost:8080/v1alpha1/graphql"
    async with websockets.connect(uri, extra_headers=headers) as websocket:
        await websocket.send(subscription.render())
        while True:
            greeting = await websocket.recv()
            print(f"< {greeting}")


def main():
    asyncio.get_event_loop().run_until_complete(user_listener())

我正在使用python websockets来实现一个使用Hasura graphql订阅的简单侦听器。然而,当我运行上面的程序时,我遇到了以下异常。(注意,我正在使用docker compose在笔记本电脑上试用hasura)

  File "listener.py", line 39, in <module>
    main()
  File "listener.py", line 35, in main
    asyncio.get_event_loop().run_until_complete(infradb_listener())
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
    return future.result()
  File "listener.py", line 27, in infradb_listener
    async with websockets.connect(uri, extra_headers=headers) as websocket:
  File "/Users/vpatil3/projects/hasura-ws-example/venv/lib/python3.6/site-packages/websockets/client.py", line 517, in __aenter__
    return await self
  File "/Users/vpatil3/projects/hasura-ws-example/venv/lib/python3.6/site-packages/websockets/client.py", line 547, in __await_impl__
    extra_headers=protocol.extra_headers,
  File "/Users/vpatil3/projects/hasura-ws-example/venv/lib/python3.6/site-packages/websockets/client.py", line 305, in handshake
    response_headers, available_subprotocols
  File "/Users/vpatil3/projects/hasura-ws-example/venv/lib/python3.6/site-packages/websockets/client.py", line 207, in process_subprotocol
    raise InvalidHandshake("no subprotocols supported")
websockets.exceptions.InvalidHandshake: no subprotocols supported

Tags: inpywswebsocketsliblineawaitextra

热门问题