TikTok-Api icon indicating copy to clipboard operation
TikTok-Api copied to clipboard

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

Open RyanCCY opened this issue 2 years ago • 28 comments

Encounters typeerror each time I try running the code.

image

Could I kindly check how to resolve? Thank you.

RyanCCY avatar Apr 06 '23 10:04 RyanCCY

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])]')

raj199108 avatar Apr 06 '23 13:04 raj199108

I observe the same issue.

mristin avatar Apr 06 '23 16:04 mristin

I have the same

max-lychko avatar Apr 06 '23 19:04 max-lychko

Downgrading playwright version to 1.30.0 fixed the issue

max-lychko avatar Apr 06 '23 19:04 max-lychko

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

JonahDMonte avatar Apr 06 '23 19:04 JonahDMonte

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

RyanCCY avatar Apr 09 '23 13:04 RyanCCY

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

JosephTJennings avatar Apr 10 '23 05:04 JosephTJennings

Same issue:

I got same error playwright 1.32

lunarforky-z avatar Apr 10 '23 12:04 lunarforky-z

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

BigdataCIST avatar Apr 11 '23 10:04 BigdataCIST

downgraded but still same error

omar-yehia avatar Apr 13 '23 13:04 omar-yehia

using playwright 1.30.0 solve this problem

lihao189 avatar Apr 14 '23 11:04 lihao189

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

shreyakannan1205 avatar Apr 17 '23 03:04 shreyakannan1205

I am also encountering this

JaidenRose avatar Apr 17 '23 22:04 JaidenRose

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

Vishdafish126 avatar Apr 18 '23 01:04 Vishdafish126

same here as well

dhu16 avatar Apr 18 '23 15:04 dhu16

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

Omak2r3a avatar Apr 19 '23 19:04 Omak2r3a

Still having this issue, anyone know the soloution?

RayBytes avatar May 02 '23 15:05 RayBytes

Still having this issue, anyone know the soloution?

Followed the link @Omak2r3a suggested and got it working

dhu16 avatar May 02 '23 20:05 dhu16

same issue

treksis avatar May 25 '23 06:05 treksis

Version 1.34.0 with the same issue

alvarogomezuria avatar Jun 02 '23 10:06 alvarogomezuria

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)

impuls64s avatar Jun 06 '23 09:06 impuls64s

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)`

reece-barker avatar Jun 15 '23 22:06 reece-barker

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

leocunhaO avatar Jun 21 '23 21:06 leocunhaO

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)

incalescence avatar Jun 26 '23 11:06 incalescence

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 :)

AlwynHD avatar Jun 28 '23 23:06 AlwynHD

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

akira9889 avatar Jun 30 '23 10:06 akira9889

Probably fixed in V6

davidteather avatar Aug 08 '23 21:08 davidteather

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())

davidteather avatar Aug 24 '24 18:08 davidteather