python格式化http请求

时间:2018-06-14 17:03:40

标签: json python-3.x post httprequest

我尝试使用AWS发送POST请求。我的问题是我一直收到错误400:错误的请求。非常感谢任何帮助!

url = 'https://api.samanage.com/incidents.json' # Set destination URL here
post_fields = {
    'incident': {
        'name': 'practice tickets for alexa',
        'priority': 'LOW',
        'requester': {
            'email': 'example@samanage.com'
        }
    }
}     # Set POST fields here

headers = {
    'cookie': 'rbzid=OquMLWfcbKxn7DHPYXDBAb6%2Bg%2FS7%2FMkG5RPBxCSy5tRDToqbLchk3q4HUPyH%2FFJ1ykIrbT7gAhVigPk9n8dmrt%2BxzZwOnF5g9Gby2ljY%2FGk%3D',
    'content-type': 'application/json',
    'x-samanage-authorization': 'Bearer **Token**',
    'accept': 'application/vnd.samanage.v2.1+json'
}

request = Request(url, urlencode(post_fields).encode(), headers=headers)
json = urlopen(request).read().decode()
print(json)

1 个答案:

答案 0 :(得分:0)

原来这在AWS in line文本编辑器中是不可能的。我必须下载AWS CLI并从CLI创建lambda函数