Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Service Now API注释以多行注释中断_Python_Api_Servicenow - Fatal编程技术网

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并留下空格-