You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
863 B

import requests # pip install requests
import jwt # pip install pyjwt
from datetime import datetime as date
# Admin API key goes here
key = ''
# Split the key into ID and SECRET
id, secret = key.split(':')
# Prepare header and payload
iat = int(date.now().timestamp())
header = {'alg': 'HS256', 'typ': 'JWT', 'kid': id}
payload = {
'iat': iat,
'exp': iat + 5 * 60,
'aud': '/admin/'
}
# Create the token (including decoding secret)
token = jwt.encode(payload, bytes.fromhex(secret), algorithm='HS256', headers=header)
# Make an authenticated request to push an image
url = 'https://mary.joefix.it/ghost/api/admin/images/upload/'
headers = {'Authorization': 'Ghost {}'.format(token)}
with open("test.jpg", "rb") as file:
files = {'file': ('test.jpg', file, 'image/jpeg')}
r = requests.post(url, files=files, headers=headers)
print(r.json())