J'ai le script Python suivant que j'utilise pour tenter de créer un ticket Zendesk. L'instruction conditionnelle suivante continue d'imprimer à l'écran et un billet n'est pas créé:Je ne sais pas comment améliorer ma journalisation des erreurs pour m'aider à diagnostiquer un problème
# Check for HTTP codes other than 201 (Created)
if response.status_code != 201:
print('Status:', response.status_code, 'Problem with the request. Exiting.')
exit()
Comment puis-je trouver plus d'informations sur l'erreur? Quels autres détails pourrais-je imprimer sur la fenêtre pour m'aider à diagnostiquer le problème?
import json
import requests
# New ticket info
subject = 'My printer is on fire!'
body = 'The smoke is very colorful.'
# Package the data in a dictionary matching the expected JSON
data = {'ticket': {'subject': subject, 'comment': {'body': body}}}
# Encode the data to create a JSON payload
payload = json.dumps(data)
# Set the request parameters
url = 'https://stackoverflow.zendesk.com/api/v2/tickets.json'
user = '[email protected]'
pwd = ''
headers = {'content-type': 'application/json'}
# Do the HTTP post request
response = requests.post(url, data=payload, auth=(user, pwd), headers=headers)
# Check for HTTP codes other than 201 (Created)
if response.status_code != 201:
print('Status:', response.status_code, 'Problem with the request. Exiting.')
exit()