【问题标题】:Post request through GAE headers issue通过 GAE 标头问题发布请求
【发布时间】:2019-02-10 12:18:14
【问题描述】:

我从 GAE Flask 服务向其他 GAE Flask 服务发送 POST 请求

try:
    service_url = 'http://localhost:4040/getservice'
    headers = {
        'Content-Type': 'application/json',
        'Cache-Control': 'no-cache',
        'Auth-Key': AUTH_KEY,
        'Customer': str(CUSTOMER)
    }

    s = Session()
    req = requests.Request('POST', service_url, data=conf, headers=headers)
    readytogo = req.prepare()

    #del readytogo.headers['Content-Lenght']
    #del readytogo.headers['Host']

    module = s.send(readytogo)

except Exception as e:
    print('error')
    print(e)
    return e

但我有这个错误:

Stripped prohibited headers from URLFetch request: ['Host', 'Content-Length']



如果我删除了该标题,我在控制台中会出现此错误:

error
'content-lenght'

页面中出现此错误:

An internal error occurred:
'exceptions.KeyError' object is not callable
See logs for full stacktrace.

GAE 不支持标头 Content-Lenght 和 Host! 如何从 GAE 向其他 GAE 端点发送 POST 请求???

【问题讨论】:

    标签: python google-app-engine flask http-headers urllib


    【解决方案1】:

    删除标题的语句中有错字,这就是导致错误的原因:

    del readytogo.headers['Content-Lenght']
    

    而不是

    del readytogo.headers['Content-Length']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-25
      • 1970-01-01
      • 2017-04-17
      • 2016-06-12
      相关资源
      最近更新 更多