Python Service Now API注释以多行注释中断
我现在打这个电话是为了对服务提出意见:Python Service Now API注释以多行注释中断,python,api,servicenow,Python,Api,Servicenow,我现在打这个电话是为了对服务提出意见: 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.pat
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)
当comment变量只有一行时,这就起作用了,但当它有多行中断时,我从字符串中删除了\n,它就起作用了。那么我该如何处理多行的请求呢?我无法去掉注释必须格式良好的空格。评论来自zendesk api
if not status 200后面的print语句以多行打印,如下所示:
this
is
a
test
非常简单,必须将请求的这一部分转换为JSON,如下所示:
data = {}
data['work_notes'] = comment
comment = json.dumps(data)
您如何删除换行符?是否尝试删除\n和\r并留下空格-