Skip to content

Commit

Permalink
Prevent unhandled exception in GetUserPosts()
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanC committed May 4, 2024
1 parent 94675f7 commit 4ac82ad
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions services/x.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ def GetUserPosts(
"https://twitter.com/i/api/graphql/XicnWRbyQ3WgVY__VataBQ/UserTweets"
)

res: Response | None = None

try:
res: Response = httpx.get(
res = httpx.get(
endpoint,
params={
"variables": json.dumps(variables),
Expand Down Expand Up @@ -141,7 +143,7 @@ def GetUserPosts(

entries = instruction["entries"]
except Exception as e:
if res.status_code == 429:
if (res) and (res.status_code == 429):
now: int = int(datetime.now().timestamp())
reset: int = int(res.headers.get("x-rate-limit-reset", now + 300))
backoff: int = reset - now
Expand Down

0 comments on commit 4ac82ad

Please sign in to comment.