Open PranavPurwar opened 11 months ago
This is a general problem it seems with id fields - There is a couple places this happens with media id, message id, etc. Also happens with datetimes, but it seems somebody else made a pr for this
ValidationError: 1 validation error for DirectMessage timestamp Input should be a valid datetime, dates after 9999 are not supported as unix timestamps [type=datetime_parsing, input_value='1704447466682555', input_type=str] For further information visit https://errors.pydantic.dev/2.5/v/datetime_parsing same error, has anyone found the answer?
ValidationError: 1 validation error for DirectMessage timestamp Input should be a valid datetime, dates after 9999 are not supported as unix timestamps [type=datetime_parsing, input_value='1704447466682555', input_type=str] For further information visit https://errors.pydantic.dev/2.5/v/datetime_parsing same error, has anyone found the answer?
Yes, you can change the fields in the dictionaries to actual dates using the datetime class, the following way:
def extract_direct_thread(data):
data["pk"] = data.get("thread_v2_id")
data["id"] = data.get("thread_id")
data["messages"] = []
for item in data["items"]:
item["thread_id"] = str(data["id"])
data["messages"].append(extract_direct_message(item))
data["users"] = [extract_user_short(u) for u in data["users"]]
if "inviter" in data:
data["inviter"] = extract_user_short(data["inviter"])
data["left_users"] = data.get("left_users", [])
if "last_activity_at" in data:
if type(data["last_activity_at"]) is not datetime:
timestamp_int = int(data["last_activity_at"]) / 1000000
data["last_activity_at"] = datetime.fromtimestamp(timestamp_int)
return DirectThread(**data)
There is one other place this problem exists, you can do this manually in the code base. I did not create a pr yet, just because this does not feel like a clear defined fix - its more like a hack.
I edited the types of some properties in types.py to get around it
Try Instagrapi SaaS with a free trial https://hikerapi.com/p/5GBWznd3
Describe the bug Trying to access direct_threads via instagrapi fails
To Reproduce
Traceback
Expected behavior The DMs should be parsed properly
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context Add any other context about the problem here.