如何在googleappengine中禁止urlphetch头警告?

2024-04-26 21:18:11 发布

您现在位置:Python中文网/ 问答频道 /正文

每当我在GAE上使用urlphetch请求外部URL时,都会收到以下警告:

WARNING  2012-03-16 15:37:21,474 urlfetch_stub.py:428] Stripped prohibited headers from URLFetch request: ['Content-Length']

我明白为什么会发生这种情况,我无法阻止根本的问题。我有没有办法抑制这个警告,以免它阻塞日志?当然,我仍然想知道urlphetch想要记录的任何其他警告/错误。在


Tags: frompyurl警告requestcontentheaderswarning
2条回答

这个警告很烦人。在

这里有一个补丁。它也适用于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

无法从日志中抑制它,您必须抑制Content-type头。在

相关问题 更多 >