question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] - Code doesn't return anything.

See original GitHub issue

I don’t get any output from any code, even the examples provided with the package and in the readme

import logging
from TikTokApi import TikTokApi

with TikTokApi(logging_level=logging.INFO) as api:
    for trending_video in api.trending.videos(count=50):
        print(trending_video.author.username)

I’ve tried reinstalling it, installing it from outside the venv, reinstalling playwright, passing the cookie to the API and nothing changed. Is anyone else having the same issue?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:8
  • Comments:19

github_iconTop GitHub Comments

13reactions
adamd01commented, Jun 7, 2022

I was having this issue, but I noticed the url generated worked fine in my browser

So I exported the cookies from my browser (I’m logged into TikTok) into cookies.json and then was able to use the below to set those cookies in all requests through the api

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

This is working for me

5reactions
dhudsmithcommented, Jun 8, 2022

Here’s the step-by-step that worked for me, @Wathfea:

  1. Install this cookie manager extension for Chrome (others may work): https://chrome.google.com/webstore/detail/cookiemanager-cookie-edit/
  2. Log into TikTok using Chrome
  3. Using the cookie manager extension, view all cookies from tiktok.
  4. Select and export all as a cookies.json file. These will have the keys “name” and “value”.
  5. Use the code provided by @adamd01
Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Why does my code not return anything - Stack Overflow
bisection only returns if f(c) == 0 but f() does not have a Return statement, so that will never happen. Past that, once...
Read more >
Function '<procedurename>' doesn't return a value on all code ...
To correct this error. Check your control flow logic and make sure you assign a value before every statement that causes a return....
Read more >
The output of functions that don't return anything should not be ...
If a function does not return anything, it makes no sense to use its output. Specifically, passing it to another function, or assigning...
Read more >
Promise.prototype.then() - JavaScript - MDN Web Docs
It immediately returns an equivalent Promise object, allowing you to chain ... doesn't return anything: p gets fulfilled with undefined ...
Read more >
Error handling, "try...catch" - The Modern JavaScript Tutorial
It won't work if the code is syntactically wrong, for instance it has unmatched ... Technically, we can use anything as an error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found