I'm trying to use requests.post to trigger the restart endpoint for an always on task. I'm getting "Unexpected status code: 301" Moved Permanently response (using allow_redirects=False for debugging).
Here's my code. I couldn't find any examples of this, and the API documentation is pretty limited.
import requests
username = '<username>'
token = '<token>'
host = 'www.pythonanywhere.com'
response = requests.post(
'https://{host}/api/v0/user/{username}/always_on/46244/restart'.format(host=host, username=username),
headers={'Authorization': 'Token {token}'.format(token=token)},
allow_redirects=False)
if response.status_code == 200:
print('CPU quota info:')
print(response.content)
else:
print('Got unexpected status code {}: {!r}'.format(response.status_code, response.content))