Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
davidteather committed Sep 22, 2021
2 parents bef2965 + f6eb822 commit 1cb0c8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions TikTokApi/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ class JSONDecodeFailure(Exception):
def __init__(self, message="TikTok sent invalid JSON back"):
self.message = message
super().__init__(self.message)


class TikTokNotAvailableError(Exception):
def __init__(self, message="The requested object is not available in this region"):
self.message = message
super().__init__(self.message)
13 changes: 13 additions & 0 deletions TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ def get_data(self, **kwargs) -> dict:
verifyFp=kwargs.get("custom_verifyFp", verifyFp),
)

if not kwargs.get("send_tt_params", False):
tt_params = None

query = {"verifyFp": verify_fp, "device_id": device_id, "_signature": signature}
url = "{}&{}".format(kwargs["url"], urlencode(query))

Expand Down Expand Up @@ -298,6 +301,12 @@ def get_data(self, **kwargs) -> dict:
raise TikTokNotFoundError(
"TikTok returned a response indicating the entity is invalid"
)
if json.get("statusCode", 200) == 10219:
# not available in this region
raise TikTokNotAvailableError(
"Content not available for this region"
)

return r.json()
except ValueError as e:
text = r.text
Expand Down Expand Up @@ -965,6 +974,10 @@ def get_music_object_full_by_api(self, id, **kwargs):
BASE_URL, id, self.__add_url_params__()
)
res = self.get_data(url=api_url, **kwargs)

if res.get("statusCode", 200) == 10203:
raise TikTokNotFoundError()

return res["musicInfo"]

def by_hashtag(self, hashtag, count=30, offset=0, **kwargs) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
setuptools.setup(
name="TikTokApi",
packages=["TikTokApi"],
version="4.0.2",
version="4.0.3",
license="MIT",
description="The Unofficial TikTok API Wrapper in Python 3.",
author="David Teather",
Expand Down

0 comments on commit 1cb0c8b

Please sign in to comment.