我正在打电话给现在的服务评论:
url = 'https://myinstance.service-
now.com/api/now/table/incident/' + sys_id
user = 'user'
pwd = 'pass'
headers = {"Content-
Type":"application/json","Accept":"application/json"}
# Do the HTTP request
response = requests.patch(url, auth=(user, pwd), headers=headers ,data="{\"work_notes\":\"" + comment + "\"}")
if response.status_code != 200:
print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
print(comment)
当注释变量只是一行时,这可以工作,但是它有多条线断开,我从字符串中删除了\ n,它确实有效。那么如何使用多行处理此请求,我无法摆脱注释必须看起来格式良好的空格。该评论来自zendesk api。
if not status 200之后的print语句将打印如下多行:
this
is
a
test
这很简单,不得不把请求的那部分变成这样的JSON:
data = {}
data['work_notes'] = comment
comment = json.dumps(data)