Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadRequestError createdAt must be an valid atproto datetime (both RFC-3339 and ISO-8601) #192

Closed
EllieTheYeen opened this issue Dec 5, 2023 · 5 comments

Comments

@EllieTheYeen
Copy link

I have started to get the following error whenever I try to post anything at all. I have not made any change in the code but both reposts and normal posts will throw the following error:

BadRequestError(Response(success=False, status_code=400, content=XrpcError(error='InvalidRequest', message='Invalid app.bsky.feed.repost record: createdAt must be an valid atproto datetime (both RFC-3339 and ISO-8601)'), headers=Headers({'date': 'Tue, 05 Dec 2023 01:34:08 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '148', 'connection': 'keep-alive', 'x-powered-by': 'Express', 'access-control-allow-origin': '*', 'ratelimit-limit': '5000', 'ratelimit-remaining': '4997', 'ratelimit-reset': '1701743648', 'ratelimit-policy': '5000;w=3600', 'etag': 'W/"94-6peGxeMN8ENNthf4a1NzrR9XOkg"', 'vary': 'Accept-Encoding'})))

I think Bsky has changed something that causes this issue

@EllieTheYeen
Copy link
Author

Noticed that this might be something I did wrong as I had used

datetime.datetime.now().isoformat()

instead of

datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%I:%SZ")

@DavidBuchanan314
Copy link

DavidBuchanan314 commented Dec 5, 2023

By the way, here's how I generate my timestamps, which perfectly matches the output of JS's Date.prototype.toISOString():

import datetime
datetime.datetime.now(tz=datetime.timezone.utc).replace(tzinfo=None).isoformat(timespec="milliseconds") + "Z"

Also by the way, datetime.utcnow() is deprecated and will be removed in a future python version, see https://blog.miguelgrinberg.com/post/it-s-time-for-a-change-datetime-utcnow-is-now-deprecated

@EllieTheYeen
Copy link
Author

That is really useful to know thanks

@MarshalX
Copy link
Owner

MarshalX commented Dec 7, 2023

@EllieTheYeen The AT Protocol SDK provides and uses this method internally. Doesn't it feet your needs?

from atproto import Client
client = Client()
print(client.get_current_time_iso())

@EllieTheYeen
Copy link
Author

Good to know. I had done some wrong thing internally in my code that generated the date so that is what caused the issue and not the code here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants