[英]Service Now API comment breaks with multiple line comment
我正在撥打此電話,以對服務進行評論:
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。
如果不是,則狀態為200后的打印語句以多行的形式打印如下:
this
is
a
test
這非常簡單,必須將請求的那部分轉換成這樣的JSON:
data = {}
data['work_notes'] = comment
comment = json.dumps(data)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.