ServiceNow REST附件API示例Python示例使用/ now / attachment / file endpoint将文件作为附件发布(上载)到inc

python
阅读 28 收藏 0 点赞 0 评论 0

servicenow_rest_attachment_api_python_simple_binary_example.py
#Need to install requests package for python
#easy_install requests
import requests


# Request Docs: http://docs.python-requests.org/en/master/user/quickstart/

# Set the request parameters
url = 'https://bbarnsc1.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id=81f8915bdb6ba20028927416bf961971&file_name=issue_screenshot'
# url = 'https://fejr5sb8ead6.runscope.net/api/now/attachment/file?table_name=incident&table_sys_id=81f8915bdb6ba20028927416bf961971&file_name=issue_screenshot'

# specify files to send as binary
data = open('issue_screenshot.jpg', 'rb').read()


# Eg. User name="admin", Password="admin" for this code sample.
user = 'xxxx'
pwd = 'xxxxxx'

# Set proper headers
headers = {"Content-Type":"image/jpg","Accept":"application/json"}


# Do the HTTP request
response = requests.post(url, auth=(user, pwd), headers=headers, data=data)

# Check for HTTP codes other than 200
if response.status_code != 200:
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
    exit()

# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号