isaackogan / TikTokLive

Python library to receive live stream events (comments, gifts, etc.) in realtime from TikTok LIVE.
https://isaackogan.github.io/TikTokLive/
MIT License
876 stars 174 forks source link

I'm getting an error when saving my livestream : websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200 #227

Closed KalvinThien closed 2 weeks ago

KalvinThien commented 3 months ago


[TikTokLive] INFO from C:\Users\KalvinThien\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py:612 — ! connect failed again; retrying in 5 seconds
Traceback (most recent call last):
  File "C:\Users\KalvinThien\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py", line 598, in __aiter__
    async with self as protocol:
  File "C:\Users\KalvinThien\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py", line 629, in __aenter__
    return await self
           ^^^^^^^^^^
  File "C:\Users\KalvinThien\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py", line 647, in __await_impl_timeout__
    return await self.__await_impl__()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\KalvinThien\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py", line 654, in __await_impl__
    await protocol.handshake(
  File "C:\Users\KalvinThien\AppData\Local\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py", line 325, in handshake
    raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200```
isaackogan commented 3 months ago

oof. latest version?

ajctrl commented 3 months ago

same here

[TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\protocol.py:256 — = connection is CONNECTING [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:115 — > GET /webcast/im/ws_proxy/ws_reuse_supplement/?aid=1988&app_language=en-US&app_name=tiktok_web&browser_language=en&browser_name=Mozilla&browser_online=True&browser_platform=Win32&browser_version=5.0+%28Windows+NT+10.0%3B+Win64%3B+x64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F102.0.5005.63+Safari%2F537.36&cookie_enabled=True&cursor=1711906467595_7352582285280936113_1_1_0_0&internal_ext=fetch_time%3A1711906467595%7Cstart_time%3A0%7Cack_ids%3A%2C%2C%7Cflag%3A0%7Cseq%3A1%7Cnext_cursor%3A1711906467595_7352582285280936113_1_1_0_0%7Cwss_info%3A0-1711906467595-0-0&device_platform=web&focus_state=True&from_page=user&history_len=4&is_fullscreen=False&is_page_visible=True&did_rule=3&fetch_rule=1&last_rtt=0&live_id=12&resp_content_type=protobuf&screen_height=1152&screen_width=2048&tz_name=Europe%2FBerlin&referer=https%3A%2F%2Fwww.tiktok.com%2F&root_referer=https%3A%2F%2Fwww.tiktok.com%2F&msToken=&version_code=180800&webcast_sdk_version=1.3.0&update_version_code=1.3.0&uuc=1&device_id=30035502517104544078&room_id=7377420291053898497&imprp= HTTP/1.1 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:117 — > Host: webcast16-ws-useast2a.tiktok.com [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:117 — > Upgrade: websocket [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:117 — > Connection: Upgrade [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:117 — > Sec-WebSocket-Key: 6rpMnA2EUgBle4szmjl9bA== [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:117 — > Sec-WebSocket-Version: 13 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:117 — > Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:117 — > Sec-WebSocket-Protocol: echo-protocol [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:117 — > Cookie: ttwid=1%7CfCfIwvwAmOJRsG1wX3_vjqa2YQMe0iD3s4uPEC8GONo%7C1717671077%7C2a88c7917e8b5698d2fcb0ffa14c79f77b1798b0fa1137f91a3cb67ff52373a6; [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:117 — > User-Agent: Python/3.12 websockets/12.0 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:144 — < HTTP/1.1 200 OK [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Content-Length: 0 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Handshake-Msg: illegal secret key [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Handshake-Status: 417 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Tt_stable: 1 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < x-tt-trace-host: 01008286f6b7e15ddaae2127f7d6c79ac7608711f585c6f261380f41a4ef27e8bd6ec72f62ce224f5d5550eff21b70eb1b4e85459a40aed64ddc320648e1440ae8a0641b729cab995d4821f19a8529210f018e7c3f8b6cbea4344bd364e6828957cdb021d27298fef6e0ea68dd1bb28781 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < x-tt-trace-id: 00-2406061929424B00E973B7F1DD067DEE-49FA74801439E12C-00 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Server: TLB [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < X-TT-LOGID: 202406061929424B00E973B7F1DD067DEE [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < X-Origin-Response-Time: 57,23.36.66.15 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < X-Akamai-Request-ID: 1b26a33.13a323e [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Expires: Thu, 06 Jun 2024 19:29:44 GMT [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Cache-Control: max-age=0, no-cache, no-store [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Pragma: no-cache [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Date: Thu, 06 Jun 2024 19:29:44 GMT [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < X-Cache: TCP_MISS from a23-58-158-20.deploy.akamaitechnologies.com (AkamaiGHost/11.5.1-56325026) (-) [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Connection: keep-alive [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < X-Cache-Remote: TCP_MISS from a23-36-66-15.deploy.akamaitechnologies.com (AkamaiGHost/11.5.1-56325026) (-) [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < x-tt-trace-tag: id=16;cdn-cache=miss;type=dyn [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Server-Timing: cdn-cache; desc=MISS, edge; dur=499, origin; dur=57 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < Server-Timing: inner; dur=29 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:146 — < X-Parent-Response-Time: 556,23.58.158.20 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\protocol.py:1412 — ! failing connection with code 1006 [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\protocol.py:1352 — x closing TCP connection [TikTokLive] DEBUG from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\protocol.py:1497 — = connection is CLOSED [TikTokLive] INFO from AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\legacy\client.py:612 — ! connect failed again; retrying in 60 seconds

KalvinThien commented 3 months ago

version?

Im use command : pip install TikTokLive --upgrade And vs show up is : 6.0.6

zufarrizal commented 3 months ago

Traceback (most recent call last): File "c:\Users\Admin\Desktop\Minecraft\Template.py", line 24, in client.run() File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\TikTokLive\client\client.py", line 200, in run return self._asyncio_loop.run_until_complete(self.connect(kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 654, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\TikTokLive\client\client.py", line 176, in connect task: Task = await self.start(kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\TikTokLive\client\client.py", line 139, in start webcast_response: WebcastResponse = await self._web.fetch_sign_fetch() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\TikTokLive\client\web\routes\fetch_sign.py", line 142, in call raise SignAPIError( TikTokLive.client.web.routes.fetch_sign.SignAPIError: [SIGN_NOT_200] Failed request to Sign API with status code 503 and payload "b'{"code":503,"error":"API is not ready for connections yet."}'". Cancelling an overlapped future failed future: <_OverlappedFuture pending cb=[_ProactorReadPipeTransport._loop_reading()]> Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 71, in _cancel_overlapped self._ov.cancel() OSError: [WinError 6] The handle is invalid Cancelling an overlapped future failed future: <_OverlappedFuture pending cb=[_ProactorReadPipeTransport._loop_reading()]> Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 71, in _cancel_overlapped self._ov.cancel() OSError: [WinError 6] The handle is invalid

I think this is a server overload message! or I was detected by TikTok!

deepin2soul commented 3 months ago

@zufarrizal did you find solution? - i have the same problem...

isaackogan commented 3 months ago

Please confirm this is occurring still, thanks

zufarrizal commented 3 months ago

@deepin2soul you can follow my code https://github.com/zufarrizal/MinecraftSurvivalPythonTiktok

deepin2soul commented 2 months ago

@deepin2soul you can follow my code https://github.com/zufarrizal/MinecraftSurvivalPythonTiktok

    elif not response.status_code == 200:
        raise SignAPIError(
            SignAPIError.ErrorReason.SIGN_NOT_200,
            f"Failed request to Sign API with status code {response.status_code} and payload \"{response.read()}\"."
        )   
zufarrizal commented 2 months ago

@deepin2soul you can follow my code https://github.com/zufarrizal/MinecraftSurvivalPythonTiktok

    elif not response.status_code == 200:
        raise SignAPIError(
            SignAPIError.ErrorReason.SIGN_NOT_200,
            f"Failed request to Sign API with status code {response.status_code} and payload \"{response.read()}\"."
        )   

I found several problems, it seems there is a problem with the API server being full, or usually it also happens in the node version belonging to zerodytrash at certain times, where I usually do it at 7 pm UTC+7 the same thing definitely happens! maybe you can find another way. so I chose another time to run the application.

The most important thing is to run it using your own TikTok. and don't use a proxy or similar to connect.

isaackogan commented 2 weeks ago

Closed due to lack of activity. Re-open if issue persists.