不确定如何改进我的错误日志记录以帮助我诊断问题

Unsure how to improve upon my error logging to help me diagnose an issue

我使用以下 Python 脚本来尝试创建 Zendesk 票证。以下条件语句继续打印到屏幕并且未创建票证:

# Check for HTTP codes other than 201 (Created)
if response.status_code != 201:
    print('Status:', response.status_code, 'Problem with the request. Exiting.')
    exit()

如何找到有关该错误的更多信息?我可以将哪些其他详细信息打印到 window 以帮助我诊断问题?

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://Whosebug.zendesk.com/api/v2/tickets.json'
user = 'test@whosebug.com'
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()

您不需要序列化您的数据字典。按原样将其传递给 post 方法。