@NeilEtheridge you could generate the token with the below code, which includes the expiration parameter. This value is in minutes, and the max is 15 days:
import requests, json
# Disable warnings
requests.packages.urllib3.disable_warnings()
username = "portaladmin"
password = "********"
tokenURL = 'https://portal.esri.com:7443/arcgis/sharing/rest/generateToken/'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'https://portal.esri.com', 'expiration': 21600}
r = requests.post(tokenURL, data = params, verify=False)
response = json.loads(r.content)
token = response['token']
print(token)