每当我在GAE上使用urlfetch请求外部URL时,我都会收到以下警告:
WARNING 2012-03-16 15:37:21,474 urlfetch_stub.py:428] Stripped prohibited headers from URLFetch request: ['Content-Length']
我理解为什么会这样,而且我无法阻止潜在的问题。有没有办法可以抑制这个警告,以免堵塞日志?当然,我仍然想知道urlfetch想要记录的任何其他警告/错误。
答案 0 :(得分:5)
无法从日志中禁止它,您必须禁止内容类型标题。
答案 1 :(得分:0)
警告非常令人讨厌。
这是一个补丁。它也适用于urllib2,urllib3和请求。
from google.appengine.api import urlfetch
urlfetch.fetch_body = urlfetch.fetch
def fetch_patch(url, payload=None, method=1, headers={},
allow_truncated=False, follow_redirects=True,
deadline=None, validate_certificate=None):
if headers and headers.get('Content-Length', None):
del headers['Content-Length']
if headers and headers.get('Host', None):
del headers['Host']
return urlfetch.fetch_body(url, payload, method, headers,
allow_truncated, follow_redirects,
deadline, validate_certificate)
urlfetch.fetch = fetch_patch