How can I suppress the urlfetch headers warning in Google App Engine?
-
24-05-2021 - |
Question
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.
Solution
There's no way to suppress it from the logs, you'll have to suppress the Content-type header.
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow