This is the simplest way I have found to post to micro.blog by using Python 3.7+ and the library requests.
No try…except blocks to catch exceptions on purpose, no comments, just pure code and a couple of empty lines.
import requests
token = "<INSERT YOUR MICRO.BLOG TOKEN HERE>"
headers = {
"content-type": "application/x-www-form-urlencoded; charset=utf-8",
"Authorization": f"Bearer {token}"
}
content = "Hello world"
sent = requests.post(
url="https://micro.blog/micropub",
headers=headers,
data={
"h": "entry",
"content": content
}
)
Hope it could be of some help to someone. Thanks for watching!