首页 > 解决方案 > 为什么我有 python 错误 unindent does not match any external indentation level 错误

问题描述

from TikTokApi import TikTokApi 
import time 
import os
import random 

api = TikTokApi()

def getLikeCount():
    tiktoks = api.byUsername('user', count=1)
    for tiktok in tiktoks:
        likeCount = tiktok["stats"]["diggCount"]
        shareCount = tiktok["stats"]["shareCount"]
        commentCount = tiktok["stats"]["commentcount"]
        followCount = tiktok["authorStats"]["followerCount"]
        return (likeCount,shareCount,commentCount,followCount)

def fag():
    os.system("afplay -/desktop/tiktok/fag.mp3 ")


def update():
    initLikeCount = 0
    while True:
        results = getLikeCount()
        currentNumLikes = results[0]
        print("sleep time")
        time.sleep(5)

        if currentNumLikes > initLikeCount:
            newLikes = currentNumLikes - initLikeCount
            initLikeCount = currentNumLikes
            print("new like count = ",newLikes)
            for x in range(newLikes):
                print("now playing this Fag.mp3",x)
                time.sleep(random.randint(0,3))
                fag()
           else()
            print("no new likes ):")
update()
#getLikeCount() 

为什么会发生这种情况,我正在制作一个 tiktok 机器人,每次我得到一个喜欢时,我都会发出声音(顺便说一句,我在 ubuntu 上,但这也发生在 Windows 上)

标签: pythonubuntu

解决方案


声明与声明else不一致if

顺便说一句,下次使用 ctrl-K 在 StackOverflow 中对齐您的代码。


推荐阅读