halcy / Mastodon.py

Python wrapper for the Mastodon ( https://github.com/mastodon/mastodon/ ) API.
MIT License
866 stars 150 forks source link

media_update return Error 404: Record not found #358

Open retiolus opened 9 months ago

retiolus commented 9 months ago

Hi, I'm trying to update media description of an uploaded image, I get its id from the status dict but media_update always returns "Record not found..."

halcy commented 9 months ago

Hey, I don't think we've implemented editing for media dicts yet - sorry. I've been quite busy, as is tradition, with all kinds of other things - I hope to get to Mastopy again sometime soon.

ianh commented 2 weeks ago

According to the API docs, PUT /api/v1/media/:id only works before the media has been attached to a status. After that, you have to do a status update with PUT /api/v1/statuses/:id to update the media.

ianh commented 2 weeks ago

Just leaving notes from my own investigation here in case they're useful. This is a real live request body from the Mastodon web UI that updates a media description: {"status":"","in_reply_to_id":null,"media_ids":["112638435710699941"],"media_attributes":[{"id":"112638435710699941","description":"test","focus":"0.00,0.00"}],"sensitive":false,"spoiler_text":"","visibility":"public","poll":null,"language":"en"}. There doesn't seem to be a way to set media_attributes from the mastodon.py status_update function, however.

ianh commented 2 weeks ago

Here's the working code I ended up with (given a status, an attachment_id, and a description):

source = mc.status_source(status.id)
source['status'] = source['text']
del source['text']
source['media_ids'] = list(map(lambda a: str(a.id), status.media_attachments))
source['media_attributes'] = [{
    'id': attachment_id,
    'description': description,
}]
mc._Mastodon__api_request('PUT', '/api/v1/statuses/{0}'.format(str(status.id)), source, use_json=True)