Skip to content

coding a API POST request to upload image #570

Answered by neobooru
modymp asked this question in Q&A
Discussion options

You must be logged in to vote

Just putting this here for completeness as this has been solved in #572

I used noirscape's code and adapted it a bit.

import base64
import requests


def btoa(txt: str):
    return base64.b64encode(txt.encode()).decode()


# conventional names for a session include session, s and r. i use session here. pick your poison.
# the auth token is created by taking base64 encoding the `username:login_token`
# you can find the login token in the webui under Account -> Login tokens
session = requests.Session()
session.headers = {
    "Accept": "application/json",
    "Authorization": "Token " + btoa("username:01ec0fd6-2dd4-40a6-907a-c36dfec07592"),
}

API_URL = "https://booru/api"

# context manage…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by neobooru
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants