iSarabjitDhiman / TweeterPy

TweeterPy is a python library to extract data from Twitter. TweeterPy API lets you scrape data from a user's profile like username, userid, bio, followers/followings list, profile media, tweets, etc.
MIT License
123 stars 17 forks source link

TypeError: Object of type timedelta is not JSON serializable #52

Closed nedsion closed 4 months ago

nedsion commented 4 months ago

i got error: TypeError: Object of type timedelta is not JSON serializable i fix problem in line 126 utils.py:

api_limit_stats = {"total_limit": api_requests_limit, "remaining_requests_count": remaining_api_requests, "resets_after": remaining_time, "reset_after_datetime_object": str(remaining_time_datetime_object), "rate_limit_exhausted": limit_exhausted}

please update to lib

nedsion commented 4 months ago

image

iSarabjitDhiman commented 4 months ago

Hey @nedsion I kept the datetime object in the api_rate_limits on purpose so that the user can easily work with the time limits.

If you want to dump the data to a JSON file, either convert it to a string as you did above or just dump only the data not the api_rate_limits.

 with open("friends.json","w") as f:
     json.dump(friends.get("data"), f, indent=4)

Feel free to close the issue if the you have no further queries.

nedsion commented 4 months ago

Này, tôi đã cố ý giữ đối tượng datetime trong api_rate_limits để người dùng có thể dễ dàng làm việc với giới hạn thời gian.

Nếu bạn muốn kết xuất dữ liệu vào tệp JSON, hãy chuyển đổi nó thành một chuỗi như bạn đã làm ở trên hoặc chỉ kết xuất dữ liệu chứ không phải api_rate_limits.

with open("friends.json","w") as f:
    json.dump(friends.get("data"), f, indent=4)

Vui lòng đóng sự cố nếu bạn không có thắc mắc nào khác.

thank u