[PYTHON] Qiitadon icon may not be changed by API

Content of the problem

I changed the icon using mastodon.py.

from mastodon import Mastodon

mastodon = Mastodon(
    access_token = "your_access_token",
    api_base_url = 'https://qiitadon.com'
)

mastodon.account_update_credentials(avatar="path_to_image.xxx")

It was reflected the first time, but it was not reflected when I changed the image and executed it again. ** **

Reason

I don't know if it's a Qiitadon or Mastodon spec, but if I change the icon in the API

--The image is saved on the server with a different name based on the image file name at the time of upload. --If you have uploaded the same image file name before, the image saved on the server will not be updated. --The image is not updated, but the previously uploaded image is applied to the icon

So if you want to change the icon to a new one, you'll have to upload it with an image name you haven't used before.

In the case of mastodon.py, it looks like this:

avatar_file_name = "mastodonpyupload_" + mimetypes.guess_extension(avatar_mime_type)

It is probable that it was not reflected as expected from the second time onward because it was decided what the local image name was.

Countermeasures

Hit the Mastodon API directly. Use the local image name for uploading. If you want to reflect a new image, use an image name that you have never used before.

import requests

url     = "https://qiitadon.com/api/v1/accounts/update_credentials"
token   = "your_access_token"
headers = {"Authorization": "Bearer " + token}

file_name = "path_to_image.xxx"
file_data = open(file_name, "rb").read()
mime_type = "image/xxx"
files     = {"avatar": (file_name, file_data, mime_type)}

requests.patch(url, headers=headers, files=files)

If a library in another language does not have this problem, you may use it.

Recommended Posts

Qiitadon icon may not be changed by API
Django's auto_now may not be updated
[django] model mods may or may not be updated
PyQtGraph may not be available in the interpreter.
AssertionError in Poetry may be fixed by modifying pyproject.toml
Note that int64 could not be received by pyOSC