【问题标题】:Service Now API comment breaks with multiple line commentService Now API 注释因多行注释而中断
【发布时间】:2018-09-06 23:57:48
【问题描述】:

我打这个电话是为了让 cmets 立即投入使用:

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 并且它确实有效。那么如何用多行处理这个请求,我无法摆脱 cmets 必须看起来格式正确的空格。评论来自zendesk api。

if not status 200 后面的 print 语句打印如下,多行:

this
is
a
test

【问题讨论】:

标签: python api servicenow


【解决方案1】:

这很简单,必须将请求的那部分转换成这样的 JSON:

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

【讨论】:

    猜你喜欢
    • 2014-01-15
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    相关资源
    最近更新 更多