# Buggy code
def trending(self, count=30, minCursor=0, maxCursor=0, **kwargs) -> dict:
    """
    Gets trending TikToks
    """
    (
        region,
        language,
        proxy,
        maxCount,
        did,
    ) = self.__process_kwargs__(kwargs)
    kwargs["custom_did"] = did

    response = []
    first = True

    while len(response) < count:
        if count < maxCount:
            realCount = count
        else:
            realCount = maxCount

        query = {
            "count": realCount,
            "id": 1,
            "secUid": "",
            "maxCursor": maxCursor,
            "minCursor": minCursor,
            "sourceType": 12,
            "appId": 1233,
            "region": region,
            "priority_region": region,
            "language": language,
        }
        api_url = "{}api/item_list/?{}&{}".format(
            BASE_URL, self.__add_new_params__(), urlencode(query)
        )
        res = self.getData(url=api_url, **kwargs)

        for t in res.get("items", []):
            response.append(t)

        if not res["hasMore"] and not first:
            logging.info("TikTok isn't sending more TikToks beyond this point.")
            return response[:count]

        realCount = count - len(response)
        maxCursor = res["maxCursor"]
        minCursor = res["minCursor"]

        first = False

    return response[:count]


# Traceback (json.decoder.JSONDecodeError)
Invalid Response
Traceback (most recent call last):
File "/home/user/.local/lib/python3.8/site-packages/TikTokApi/tiktok.py", line 162, in getData
return r.json()
File "/home/user/.local/lib/python3.8/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/user/tiktok/tiktokhelper.py", line 33, in addUser
data = api.getUser(uniqueId)
File "/home/user/.local/lib/python3.8/site-packages/TikTokApi/tiktok.py", line 1010, in getUser
return self.getData(url=api_url, **kwargs)["userInfo"]
File "/home/user/.local/lib/python3.8/site-packages/TikTokApi/tiktok.py", line 170, in getData
raise Exception("Invalid Response")
Exception: Invalid Response

# Fixed code
def trending(self, count=30, minCursor=0, maxCursor=0, **kwargs) -> dict:
    """
    Gets trending TikToks
    """
    (
        region,
        language,
        proxy,
        maxCount,
        did,
    ) = self.__process_kwargs__(kwargs)
    kwargs["custom_did"] = did

    response = []
    first = True

    while len(response) < count:
        if count < maxCount:
            realCount = count
        else:
            realCount = maxCount

        query = {
            "count": realCount,
            "id": 1,
            "secUid": "",
            "maxCursor": maxCursor,
            "minCursor": minCursor,
            "sourceType": 12,
            "appId": 1233,
            "region": region,
            "priority_region": region,
            "language": language,
        }
        api_url = "{}api/item_list/?{}&{}".format(
            BASE_URL, self.__add_new_params__(), urlencode(query)
        )
        res = self.getData(url=api_url, **kwargs)

        for t in res.get("items", []):
            response.append(t)

        if not res["hasMore"] and not first:
            logging.info("TikTok isn't sending more TikToks beyond this point.")
            return response[:count]

        realCount = count - len(response)
        maxCursor = res["maxCursor"]

        first = False

    return response[:count]