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

[BUG] Websocket not connecting #241

Open
STRATZ-Ken opened this issue Feb 6, 2024 · 1 comment
Open

[BUG] Websocket not connecting #241

STRATZ-Ken opened this issue Feb 6, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@STRATZ-Ken
Copy link

STRATZ-Ken commented Feb 6, 2024

Describe the bug
Getting the following error : Failed to WS_RECV, ErrCode: 52, Reason: ''. This may be a libcurl error, See https://curl.se/libcurl/c/libcurl-errors.html first for more details.

To Reproduce

from curl_cffi.requests import Session, WebSocket
import json

msg_count = 0


def on_message(ws: WebSocket, message):
    global msg_count

    print("------------------------------------------------------")
    print(message)
    print("======================================================")

    msg_count += 1
    if msg_count >= 100:
        ws.close()


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


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


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


with Session() as s:
    ws = s.ws_connect(
        "wss://api.hardrocksportsbook.com/graphql-ws",
        on_open=on_open,
        on_close=on_close,
        on_message=on_message,
        on_error=on_error,
    )
    message = {"SportsbookLoginRequest": {"application": "sportsbook", "channel": "ARIZONA_ONLINE", "locale": "enus-us-x-az"}}
    tosend = json.dumps(message).encode()
    ws.send(tosend)
    ws.run_forever()

Expected behavior
The response should be {"Response":{"status":"ok","reqId":"0"}}

Versions

  • OS: Windows, Python 3.12
    certifi==2024.2.2
    cffi==1.16.0
    curl_cffi==0.6.0b9
    numpy==1.26.4
    pycparser==2.21

Additional context

  • Which session are you using? async or sync? Sync
@STRATZ-Ken STRATZ-Ken added the bug Something isn't working label Feb 6, 2024
@yifeikong
Copy link
Owner

Sorry, I can not reproduce this error, I'm getting:

ErrCode: 22, Reason: 'Refused WebSockets upgrade: 403'

@yifeikong yifeikong changed the title [BUG] [BUG] Websocket not connecting Feb 17, 2024
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