我从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请求?
答案 0 :(得分:1)
您在删除标题的语句中有错别字,这就是导致错误的原因:
del readytogo.headers['Content-Lenght']
代替
del readytogo.headers['Content-Length']