davidteather / TikTok-Api

The Unofficial TikTok API Wrapper In Python
https://davidteather.github.io/TikTok-Api
MIT License
4.9k stars 982 forks source link

[BUG] - playwright._impl._api_types.Error: TypeError: undefined is not an object (evaluating 'S[A][m(a[oprand[1]],oprand[1])]') #1012

Open RyanCCY opened 1 year ago

RyanCCY commented 1 year ago

Encounters typeerror each time I try running the code.

image

Could I kindly check how to resolve? Thank you.

raj199108 commented 1 year ago

Same issues with me as well.

Traceback (most recent call last): File "/home/rajkumar/TikTok-Api/tiktok_test.py", line 16, in for trending_video in api.trending.videos(count=50): File "/home/rajkumar/TikTok-Api/TikTokApi/api/trending.py", line 59, in videos res = Trending.parent.get_data(path, ttwid=ttwid, kwargs) File "/home/rajkumar/TikTok-Api/TikTokApi/tiktok.py", line 266, in get_data ) = asyncio.get_event_loop().run_until_complete( File "/usr/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "/home/rajkumar/TikTok-Api/TikTokApi/browser_utilities/browser.py", line 212, in sign_url evaluatedPage = await page.evaluate( File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/async_api/_generated.py", line 8590, in evaluate await self._impl_obj.evaluate( File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_page.py", line 411, in evaluate return await self._main_frame.evaluate(expression, arg) File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_frame.py", line 277, in evaluate await self._channel.send( File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 61, in send return await self._connection.wrap_api_call( File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 461, in wrap_api_call return await cb() File "/home/rajkumar/.virtualenvs/tik/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 96, in inner_send result = next(iter(done)).result() playwright._impl._api_types.Error: TypeError: undefined is not an object (evaluating 'S[A][m(a[oprand[1]],oprand[1])]')**

mristin commented 1 year ago

I observe the same issue.

max-lychko commented 1 year ago

I have the same

max-lychko commented 1 year ago

Downgrading playwright version to 1.30.0 fixed the issue

JonahDMonte commented 1 year ago

Downgrading playwright version to 1.30.0 fixed the issue

worked for me too. is there a way to pin this to the top or smth? idk im new to github. ty for your solution mr genius

RyanCCY commented 1 year ago

Thanks guys! awesome, managed to downgrade playwright version and seems to be compiling without errors. However, I can't seem to be generating any results.

image

Would anyone know the solution to this? Or able to paste a sample code for me to run? Thanks so much once again

JosephTJennings commented 1 year ago

Same issue; even after the playwright version changes it still occurs.

lunarforky-z commented 1 year ago

Same issue:

I got same error playwright 1.32

BigdataCIST commented 1 year ago

Thanks guys! awesome, managed to downgrade playwright version and seems to be compiling without errors. However, I can't seem to be generating any results.

image

Would anyone know the solution to this? Or able to paste a sample code for me to run? Thanks so much once again

Same issue after using playwright 1.3.0

omar-yehia commented 1 year ago

downgraded but still same error

lihao189 commented 1 year ago

using playwright 1.30.0 solve this problem

shreyakannan1205 commented 1 year ago

I am having the same issue after downgrading to 1.30.0 as well this is my command for downgrading: python3.8 -m pip install playwright==1.30.0

Screenshot 2023-04-16 at 10 15 03 PM
JaidenRose commented 1 year ago

I am also encountering this

Vishdafish126 commented 1 year ago

had the same issue with 1.32, got the error, downgraded to 1.30 and compile without issues but don't actually return any results

dhu16 commented 1 year ago

same here as well

Omak2r3a commented 1 year ago

had the same issue with 1.32, got the error, downgraded to 1.30 and compile without issues but don't actually return any results

Check this out

RayBytes commented 1 year ago

Still having this issue, anyone know the soloution?

dhu16 commented 1 year ago

Still having this issue, anyone know the soloution?

Followed the link @Omak2r3a suggested and got it working

treksis commented 1 year ago

same issue

alvarogomezuria commented 1 year ago

Version 1.34.0 with the same issue

impuls64s commented 1 year ago

how to solve this problem? code is not working

from TikTokApi import TikTokApi

# Watch https://www.youtube.com/watch?v=-uCt1x8kINQ for a brief setup tutorial
with TikTokApi() as api:
    for trending_video in api.trending.videos(count=50):
        # Prints the author's username of the trending video.
        print(trending_video.author.username)
reece-barker commented 1 year ago

I still have no idea, i am so lost with this. I am running on MacOS gives me the same error despite running different forms and code etc...

Traceback (most recent call last): File "/Users/reece_barker/GitHub/RustNite TikTok/run.py", line 26, in <module> for video in api.trending.videos(): File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/TikTokApi/api/trending.py", line 59, in videos res = Trending.parent.get_data(path, ttwid=ttwid, **kwargs) File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/TikTokApi/tiktok.py", line 266, in get_data ) = asyncio.get_event_loop().run_until_complete( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete return future.result() File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/TikTokApi/browser_utilities/browser.py", line 212, in sign_url evaluatedPage = await page.evaluate( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/async_api/_generated.py", line 8658, in evaluate await self._impl_obj.evaluate( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_page.py", line 395, in evaluate return await self._main_frame.evaluate(expression, arg) File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_frame.py", line 277, in evaluate await self._channel.send( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 61, in send return await self._connection.wrap_api_call( File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 482, in wrap_api_call return await cb() File "/Users/reece_barker/.pyenv/versions/3.10.3/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 97, in inner_send result = next(iter(done)).result() playwright._impl._api_types.Error: TypeError: undefined is not an object (evaluating 'S[A][m(a[oprand[1]],oprand[1])]')

my code:

`from TikTokApi import TikTokApi import json

def get_cookies_from_file(): with open('cookies.json') as f: cookies = json.load(f)

cookies_kv = {}
for cookie in cookies:
    cookies_kv[cookie['name']] = cookie['value']

return cookies_kv

cookies = get_cookies_from_file()

def get_cookies(**kwargs): return cookies

api = TikTokApi()

api._get_cookies = get_cookies # This fixes issues the api was having

for video in api.trending.videos(): print(video.author.username)`

leocunhaO commented 1 year ago

@RyanCCY how were you able to downgrade the playright version to 1.30.0? did you fix the issue?

incalescence commented 1 year ago

The steps I took to resolve this issue

def get_cookies_from_file(): with open('cookies.json') as f: cookies = json.load(f)

cookies_kv = {}
for cookie in cookies:
    cookies_kv[cookie['name']] = cookie['value']

return cookies_kv

cookies = get_cookies_from_file()

def get_cookies(**kwargs): return cookies

with TikTokApi() as api: api._get_cookies = get_cookies for trending_video in api.trending.videos(count=10): print(trending_video.author.username)

AlwynHD commented 1 year ago

The steps I took to resolve this issue

  • Remove current version of playright: playwright uninstall --all
  • Install version 1.30.0 of playwright: pip install --force-reinstall -v "playwright==1.30.0"
  • Logged into Tiktok on Chrome and exported my cookies as JSON using EditThisCookie image
  • Pasted all cookie data into cookies.json referencing this comment in another issue

Here is the code I had:

from TikTokApi import TikTokApi
import json

def get_cookies_from_file():
    with open('cookies.json') as f:
        cookies = json.load(f)

    cookies_kv = {}
    for cookie in cookies:
        cookies_kv[cookie['name']] = cookie['value']

    return cookies_kv

cookies = get_cookies_from_file()

def get_cookies(**kwargs):
    return cookies

with TikTokApi() as api:
    api._get_cookies = get_cookies
    for trending_video in api.trending.videos(count=10):
        print(trending_video.author.username)

This worked perfectly for me. Thanks :)

akira9889 commented 1 year ago

The steps I took to resolve this issue

The directory structure is as follows:

tiktok ├── cookies.json ├── docker-compose.yml ├── Dockerfile └── tiktok.py

Dockerfile

FROM mcr.microsoft.com/playwright:v1.30.0-focal

RUN apt-get update && apt-get install -y python3-pip

# Install Playwright and then install the browsers:
RUN pip install --force-reinstall -v "playwright==1.30.0"
RUN playwright install
RUN pip3 install TikTokApi

WORKDIR /app

COPY . .

docker-compose.yml

version: '3.8'
services:
  python-app:
    build: .
    volumes:
      - .:/app
    tty: true

tiktok.py

from TikTokApi import TikTokApi
import json

def get_cookies_from_file():
    with open('./cookies.json') as f:
        cookies = json.load(f)

    cookies_kv = {}
    for cookie in cookies:
        cookies_kv[cookie['name']] = cookie['value']

    return cookies_kv

cookies = get_cookies_from_file()

def get_cookies(**kwargs):
    return cookies

with TikTokApi() as api:
    api._get_cookies = get_cookies
    for trending_video in api.trending.videos(count=10):
        print(trending_video.author.username)

cookies.json

The cookies.json file is exported using the Chrome extension EditThisCookie to get the cookie information from TikTok. (This assumes that you are already logged in to TikTok.)

When you press the export button, it is copied to the clipboard, so you can paste it directly into cookies.json.

Then, by executing the following commands, I was able to retrieve the user.

Check the current directory

pwd

Output ~/tiktok

Enter the container

docker-compose exec python-app bash

Execute the following in the container

root@:/app# python3 tiktok.py
davidteather commented 1 year ago

Probably fixed in V6

davidteather commented 3 months ago

This is a weird issue, I can't seem to figure it out. But it works if you specify webkit as your browser If anyone else looks into it, I've found this

user_agent = await session.page.evaluate("() => navigator.userAgent")

this throws the error

user_agent = await session.page.evaluate("() => navigator.userAgentData")

Doesn't, and most other attribute accesses seem to work fine. It feels like a weird way that playwright must've changed handling this in 1.4.0

But this script works normally so it might be an issue on how this library is assigning pages?

import asyncio
from playwright.async_api import async_playwright

async def run():
    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch(headless=True)  # Set headless=True to run without UI
        page = await browser.new_page()
        await page.goto('https://tiktok.com')

        user_agent = await page.evaluate("() => navigator.userAgent")
        print(user_agent)

        await page.wait_for_timeout(5000)  
        await browser.close()

asyncio.run(run())