Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Long running async.py" in the example cannot run normally [BUG] #270

Open
xjaslkjkalsd opened this issue Mar 11, 2024 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@xjaslkjkalsd
Copy link

"""
WIP: this has not been implemented yet.
"""
import asyncio
from curl_cffi import requests


async def on_message(ws, message):
    print(message)


async def on_error(ws, error):
    print(error)


async def on_open(ws):
    print("For websockets, you need to set $wss_proxy environment variable!\n"
          "$https_proxy will not work!")
    print(">>> Websocket open!")


async def on_close(ws):
    print("<<< Websocket closed!")


async def main():
    async with requests.AsyncSession() as s:
        ws = await s.ws_connect(
            "wss://api.gemini.com/v1/marketdata/BTCUSD",
            on_open=on_open,
            on_close=on_close,
            on_message=on_message,
            on_error=on_error,
        )
        ws.run_forever()


asyncio.run(main())

Terminal error

Traceback (most recent call last):
  File "/Users/baobao/MyDesktop/python/func-proxy/test.py", line 38, in <module>
    asyncio.run(main())
  File "/opt/homebrew/Cellar/python@3.10/3.10.13_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/homebrew/Cellar/python@3.10/3.10.13_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/baobao/MyDesktop/python/func-proxy/test.py", line 28, in main
    ws = await s.ws_connect(
  File "/opt/homebrew/lib/python3.10/site-packages/curl_cffi/requests/session.py", line 978, in ws_connect
    self._set_curl_options(curl, "GET", url, *args, **kwargs)
TypeError: BaseSession._set_curl_options() got an unexpected keyword argument 'on_open'
@xjaslkjkalsd xjaslkjkalsd added the bug Something isn't working label Mar 11, 2024
@yifeikong
Copy link
Owner

The websocket support is still experimental, the sync api is more usable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants