简体   繁体   English

Service Now API注释以多行注释中断

[英]Service Now API comment breaks with multiple line comment

I am making this call to make comments to service now: 我正在拨打此电话,以对服务进行评论:

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)

And this works when the comment variable is just one line, but with multiple lines it breaks, I removed the \\n from string and it does work. 当注释变量仅是一行时,这是可行的,但是在多行中断的情况下,我从字符串中删除了\\ n,它确实起作用了。 So how do I process this request with multiple lines, I cant get rid of the spaces the comments have to look well formatted. 因此,如何处理多行请求,我无法摆脱注释必须格式正确的空格。 The comment is coming from zendesk api. 该评论来自zendesk API。

The print statement after the if not status 200 prints as following with multiple lines: 如果不是,则状态为200后的打印语句以多行的形式打印如下:

this
is
a
test

It was pretty simple, had to turn that part of the request into a JSON like this: 这非常简单,必须将请求的那部分转换成这样的JSON:

data = {}
data['work_notes'] = comment
comment = json.dumps(data)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM