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

时间:2018-08-24 15:45:14

标签: 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.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之后的打印语句以多行的形式打印如下:

this
is
a
test

1 个答案:

答案 0 :(得分:0)

这非常简单,必须将请求的这一部分转换为JSON,如下所示:

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