isaackogan / TikTokLive

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

not able to connect #16

Closed SwiftyFlow closed 2 years ago

SwiftyFlow commented 2 years ago

Unclosed client session client_session: <aiohttp.client.ClientSession

isaackogan commented 2 years ago

More context?

SwiftyFlow commented 2 years ago

Well I've been following the read me to the point and:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/base.py", line 107, in __fetch_room_info response = await self._http.get_json_object_from_webcast_api("room/info/", self._client_params)

Plus plenty of other lines

SwiftyFlow commented 2 years ago

`import uuid

from TikTokLive import TikTokLiveClient from TikTokLive.types.events import FollowEvent, LikeEvent, JoinEvent, GiftEvent

import firebase_admin from firebase_admin import credentials from firebase_admin import db

cred = credentials.Certificate('myFirebaseCert.json')

firebase_admin.initialize_app(cred, { 'databaseURL': 'https://myFireBaseLink.firebaseio.com/' })

ref = db.reference('py/') perm_ref = ref.child('perm') rows_ref = ref.child('rows')

client: TikTokLiveClient = TikTokLiveClient(unique_id="@myUsername", **( {

Whether to process initial data (cached chats, etc.)

        "process_initial_data": True,

        # Connect info (viewers, stream status, etc.)
        "fetch_room_info_on_connect": True,
    }
)

)

@client.on("follow") async def on_follow(event: FollowEvent): username = event.user.uniqueId rows_ref.update({ str(uuid.uuid4()): { 'type': 'widget', 'username': '@' + username, 'thanksBottom': '' } })

@client.on("like") async def on_like(event: LikeEvent): username = event.user.uniqueId rows_ref.update({ str(uuid.uuid4()): { 'type': 'thanks', 'username': '@' + username, 'thanksBottom': 'Thanks for the like!' } })

@client.on("join") async def on_join(event: JoinEvent): username = event.user.uniqueId rows_ref.update({ str(uuid.uuid4()): { 'type': 'thanks', 'username': '@' + username, 'thanksBottom': 'Thanks for joining!' } })

@client.on("gift") async def on_gift(event: GiftEvent): username = event.user.uniqueId perm_ref.update({ 'username': '@' + username })

client.add_listener("follow", on_follow) client.add_listener("like", on_like) client.add_listener("join", on_join) client.add_listener("gift", on_gift)

if name == 'main': client.run() `

SwiftyFlow commented 2 years ago

raise FailedConnection(message) TikTokLive.types.errors.FailedConnection: 'NoneType' object has no attribute 'get'

isaackogan commented 2 years ago

Please post the full stacktrace, top to bottom, in a code block if you want help. Use three of this ` symbol before and after the stacktrace.


like this

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED]

This sounds like a certificate issue. You probably need to install certs for your Python.

Follow these instructions: https://cdn.discordapp.com/attachments/946228281059975189/948675757499088916/B2ED3006-893D-476C-AB43-ED7F704E744F.jpg

SwiftyFlow commented 2 years ago
ERROR:root:Traceback (most recent call last):
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1081, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1111, in _create_connection_transport
    await waiter
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/sslproto.py", line 528, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/sslproto.py", line 188, in feed_ssldata
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 944, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/base.py", line 90, in __fetch_room_id
    html: str = await self._http.get_livestream_page_html(self.__unique_id)
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/http.py", line 93, in get_livestream_page_html
    response: bytes = await self.__aiohttp_get_bytes(f"{TikTokHTTPClient.TIKTOK_URL_WEB}@{unique_id}/live")
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/http.py", line 65, in __aiohttp_get_bytes
    async with self.session.get(request_url, headers=self.headers, timeout=self.timeout, proxy=self.proxy_container.get()) as request:
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 988, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host www.tiktok.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')]

Failed to retrieve room id from page source
ERROR:root:Traceback (most recent call last):
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1081, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1111, in _create_connection_transport
    await waiter
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/sslproto.py", line 528, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/sslproto.py", line 188, in feed_ssldata
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 944, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/base.py", line 107, in __fetch_room_info
    response = await self._http.get_json_object_from_webcast_api("room/info/", self._client_params)
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/http.py", line 122, in get_json_object_from_webcast_api
    response: dict = await self.__aiohttp_get_json(self.TIKTOK_URL_WEBCAST + path, params)
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/http.py", line 80, in __aiohttp_get_json
    async with self.session.get(request_url, headers=self.headers, timeout=self.timeout, proxy=self.proxy_container.get()) as request:
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/aiohttp/connector.py", line 988, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host webcast.tiktok.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')]

Failed to retrieve room info from webcast api
Traceback (most recent call last):
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/base.py", line 208, in _connect
    if self.__room_info.get("status", 4) == 4:
AttributeError: 'NoneType' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/flowpottevin/PycharmProjects/fireTok/FireTokMain.py", line 106, in <module>
    client.run()
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/base.py", line 284, in run
    self.loop.run_until_complete(self._connect())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/client.py", line 39, in _connect
    result: str = await super(TikTokLiveClient, self)._connect()
  File "/Users/flowpottevin/PycharmProjects/fireTok/venv/lib/python3.9/site-packages/TikTokLive/client/base.py", line 238, in _connect
    raise FailedConnection(message)
TikTokLive.types.errors.FailedConnection: 'NoneType' object has no attribute 'get'

Process finished with exit code 1
SwiftyFlow commented 2 years ago

Thanks mate! certificate solution was spot on

isaackogan commented 2 years ago

Glad to help!