Open RyanCCY opened 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
I observe the same issue.
I have the same
Downgrading playwright version to 1.30.0 fixed the issue
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
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.
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; even after the playwright version changes it still occurs.
Same issue:
I got same error playwright 1.32
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.
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
downgraded but still same error
using playwright 1.30.0 solve this problem
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
I am also encountering this
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
same here as well
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
Still having this issue, anyone know the soloution?
Still having this issue, anyone know the soloution?
Followed the link @Omak2r3a suggested and got it working
same issue
Version 1.34.0 with the same issue
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)
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)`
@RyanCCY how were you able to downgrade the playright version to 1.30.0? did you fix the issue?
playwright uninstall --all
pip install --force-reinstall -v "playwright==1.30.0"
cookies.json
referencing this comment in another issue
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)
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
- Pasted all cookie data into
cookies.json
referencing this comment in another issueHere 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 :)
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
Probably fixed in V6
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())
Encounters typeerror each time I try running the code.
Could I kindly check how to resolve? Thank you.