[英]Service Now API comment breaks with multiple line comment
我正在拨打此电话,以对服务进行评论:
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。
如果不是,则状态为200后的打印语句以多行的形式打印如下:
this
is
a
test
这非常简单,必须将请求的那部分转换成这样的JSON:
data = {}
data['work_notes'] = comment
comment = json.dumps(data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.