【问题标题】:python formatting http requestspython格式化http请求
【发布时间】:2018-06-14 17:03:40
【问题描述】:

我正在尝试使用 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)

【问题讨论】:

  • 另外值得注意的是,如果我完全取出标题,则会收到 401 Unauthorized 错误代码

标签: json python-3.x post httprequest


【解决方案1】:

事实证明,这在 AWS 行内文本编辑器中是不可能的。我必须下载 AWS CLI 并从 CLI 创建 lambda 函数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多