문제

Whenever I request an external URL using urlfetch on GAE I get the following warning:

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

I understand why this is happening, and that I won't be able to stop the underlying issue. Is there a way I can suppress this warning so that it doesn't clog up the logs? Of course I'd still want to know about any other warnings/errors that urlfetch wanted to log.

도움이 되었습니까?

해결책

There's no way to suppress it from the logs, you'll have to suppress the Content-type header.

다른 팁

The warning is very annoying.

Here is a patch for that. It works for urllib2, urllib3, and Requests as well.

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top