# Buggy code
def userPosts(
    self, userID, secUID, count=30, language="en", region="US", proxy=None
) -> dict:
    """Returns a dictionary listing TikToks given a user's ID and secUID

    :param userID: The userID of the user, which TikTok assigns.
    :param secUID: The secUID of the user, which TikTok assigns.
    :param count: The number of posts to return.
                  Note: seems to only support up to ~2,000
    :param language: The 2 letter code of the language to return.
                     Note: Doesn't seem to have an affect.
    :param region: The 2 letter region code.
                   Note: Doesn't seem to have an affect.
    :param proxy: The IP address of a proxy to make requests from.
    """
    response = []
    maxCount = 50
    maxCursor = 0
    first = True

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

        query = {
            "count": realCount,
            "id": userID,
            "type": 1,
            "secUid": secUID,
            "maxCursor": maxCursor,
            "minCursor": 0,
            "sourceType": 8,
            "appId": 1233,
            "region": region,
            "language": language,
        }
        api_url = "{}api/item_list/?{}&{}".format(
            BASE_URL, self.__add_new_params__(), urlencode(query)
        )
        b = browser(api_url, proxy=proxy)
        res = self.getData(b, proxy=proxy)

        if "items" in res.keys():
            for t in res["items"]:
                response.append(t)

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

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

        first = False

    return response[:count]


# Traceback (json.decoder.JSONDecodeError)
api.byHashtag('love')

{'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36', 'accept-encoding': 'gzip, deflate, br', 'accept': 'application/json, text/plain, */*', 'Connection': 'keep-alive', 'authority': 'm.tiktok.com', 'method': 'GET', 'path': '/share/item/list?aid=1988&amp;app_name=tiktok_web&amp;device_platform=web&amp;referer=&amp;user_agent=Mozilla%2F5.0+(Windows+NT+10.0%3B+Win64%3B+x64)+AppleWebKit%2F537.36+(KHTML,+like+Gecko)+Chrome%2F84.0.4147.125+Safari%2F537.36&amp;cookie_enabled=true&amp;screen_width=2560&amp;screen_height=1440&amp;browser_language=&amp;browser_platform=&amp;browser_name=&amp;browser_version=&amp;browser_online=true&amp;timezone_name=&amp;priority_region=&amp;appId=1233&amp;appType=m&amp;isAndroid=false&amp;isMobile=false&amp;isIOS=false&amp;OS=windows&amp;did=822148675&amp;region=US&amp;secUid=&amp;id=4231&amp;type=3&amp;count=30&amp;minCursor=0&amp;maxCursor=0&amp;shareUid=&amp;recType=&amp;lang=en&amp;verifyFp=AaN99VturDQ2&amp;_signature=_02B4Z6wo00f01SDv8tgAAIBB6rMaD8GoX..ZAABdw74', 'scheme': 'https', 'accept-language': 'en-US,en;q=0.9', 'referrer': 'https://www.tiktok.com/', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-site'}
Converting response to JSON failed response is below (probably empty)
Traceback (most recent call last):
File "~/PycharmProjects/backup_scrapers/vevn/lib/python3.8/site-packages/TikTokApi/tiktok.py", line 85, in getData
return r.json()
File "~/PycharmProjects/backup_scrapers/vevn/lib/python3.8/site-packages/requests/models.py", line 898, in json
return complexjson.loads(self.text, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.8/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 "<input>", line 1, in <module>
File "~/PycharmProjects/backup_scrapers/vevn/lib/python3.8/site-packages/TikTokApi/tiktok.py", line 357, in byHashtag
res = self.getData(api_url, b, proxy=proxy, language=language)
File "~/PycharmProjects/backup_scrapers/vevn/lib/python3.8/site-packages/TikTokApi/tiktok.py", line 91, in getData
raise Exception('Invalid Response')
Exception: Invalid Response

# Fixed code
def userPosts(
    self, userID, secUID, count=30, language="en", region="US", proxy=None
) -> dict:
    """Returns a dictionary listing TikToks given a user's ID and secUID

    :param userID: The userID of the user, which TikTok assigns.
    :param secUID: The secUID of the user, which TikTok assigns.
    :param count: The number of posts to return.
                  Note: seems to only support up to ~2,000
    :param language: The 2 letter code of the language to return.
                     Note: Doesn't seem to have an affect.
    :param region: The 2 letter region code.
                   Note: Doesn't seem to have an affect.
    :param proxy: The IP address of a proxy to make requests from.
    """
    response = []
    maxCount = 50
    maxCursor = 0
    first = True

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

        query = {
            "count": realCount,
            "id": userID,
            "type": 1,
            "secUid": secUID,
            "maxCursor": maxCursor,
            "minCursor": 0,
            "sourceType": 8,
            "appId": 1233,
            "region": region,
            "priority_region": region,
            "language": language,
        }
        api_url = "{}api/item_list/?{}&{}".format(
            BASE_URL, self.__add_new_params__(), urlencode(query)
        )
        b = browser(api_url, proxy=proxy)
        res = self.getData(b, proxy=proxy)

        if "items" in res.keys():
            for t in res["items"]:
                response.append(t)

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

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

        first = False

    return response[:count]