davidteather / TikTok-Api

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

ERROR Message when running gettrending.py #14

Closed Steenos closed 4 years ago

Steenos commented 4 years ago

Hello! I was able to get everything working up to this point. When I run gettrending.py the browser window opens and begins to load the page, then I get this error message.

Traceback (most recent call last): File "gettrending.py", line 11, in trending = api.trending(results) File "C:\Users\steee\Anaconda3\envs\tiktok\lib\site-packages\TikTokApi\tiktok.py", line 229, in trending if count > len(response) and str(data['body']['hasMore']) == "True": KeyError: 'body'

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.70. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

davidteather commented 4 years ago

Are you able to add a new line above line 11 to do print(data).

What’s the response once you do that?

davidteather commented 4 years ago

Actually, sorry I made that mistake. I thought this was an issue on my TikTokBot repo.

What value do you have results set to? Also is your directory to browsermob proxy correct?

Steenos commented 4 years ago

I changed the results value to 2 and now it seems to work. Is there a way to return the more results? And how would I go about returning a video url to download?

Steenos commented 4 years ago

Just figured out how to return the url by looking at the json file! But it would be nice to be able to return more values. results=2 is the most it seems to allow.

davidteather commented 4 years ago

Yeah that's weird. In the unit tests for the api allows for over 100 to be fetched at a single time.

Can you try to run

from TikTokApi import TikTokapi
import requests

api = TikTokapi("path/to/browsermob-proxy")

trending = api.trending(10)

verbose = 0
count = 10
import requests

while True:
    url = "https://m.tiktok.com/share/item/list?id=&type=5&count=" + \
        str(count) + "&minCursor=0&maxCursor=0&_signature=" + \
        api.signature
    r = requests.get(url, headers={"authority": "m.tiktok.com", "method": "GET", "path": url.split("https://m.tiktok.com")[0], "scheme": "https", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                                    "accept-encoding": "gzip, deflate, br", "accept-language": "en-US,en;q=0.9", "cache-control": "max-age=0", "upgrade-insecure-requests": "1",
                                    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"})

    data = r.json()
    response = []

    if data["statusCode"] != 0:
        if verbose == 1:
            print("Invalid Signature Retrying")
    else:
        for tiktok in data["body"]["itemListData"]:
            response.append(tiktok)
        while True:
            print(data)
            if count > len(response) and str(data['body']['hasMore']) == "True":
                url = "https://m.tiktok.com/share/item/list?id=&type=5&count=" + \
                    str(count - len(response)) + "&minCursor=0&maxCursor=" + \
                    data['body']['maxCursor'] + \
                    "&_signature=" + api.signature

                r = requests.get(url, headers={"authority": "m.tiktok.com", "method": "GET", "path": url.split("https://m.tiktok.com")[0], "scheme": "https", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                                                "accept-encoding": "gzip, deflate, br", "accept-language": "en-US,en;q=0.9", "cache-control": "max-age=0", "upgrade-insecure-requests": "1",
                                                "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"})
                data = r.json()
                if data["statusCode"] == 0:
                    for tiktok in data["body"]["itemListData"]:
                        response.append(tiktok)
            else:
                print(response)
                break
Steenos commented 4 years ago

hmm, running that gives the same error.

davidteather commented 4 years ago

Does it print out anything beforehand?

Steenos commented 4 years ago

in server.log it looks like its failing to start jetty server

davidteather commented 4 years ago

Does it open the browser before giving you the error?

Steenos commented 4 years ago

Yes, this is the error: (main) Failed to start Jetty server. Aborting. java.net.BindException: Address already in use: bind

davidteather commented 4 years ago

Can you try to close any running java programs or other programs that may be binding to a port?

husligc commented 4 years ago

any plans to make a follow and unfollow function?

davidteather commented 4 years ago

any plans to make a follow and unfollow function?

Not currently because to login captcha bypass is required. If I were to create account login features the user would have to solve the captcha manually until a better option is found.

husligc commented 4 years ago

Would you be interested in helping me make just a simple follow/unfollow script for myself? Thanks