8

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.

alnorth29
  • 3,525
  • 2
  • 34
  • 50

2 Answers2

5

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

Guido van Rossum
  • 16,690
  • 3
  • 46
  • 49
  • Is that possible when I don't control the server it's making a request to? It's a Google API that I'm making calls to. – alnorth29 Mar 19 '12 at 10:58
  • 4
    Unless I'm mistaken, urlfetch is complaining about a header you are setting in the request, so the behavior of the server doesn't enter into it. (And I can't see why it Content-Length would be prohibited in the response -- wouldn't that make almost all responses invalid?) – Guido van Rossum Mar 19 '12 at 16:37
  • Ah, OK. That makes more sense. Thanks! – alnorth29 Mar 20 '12 at 07:39
  • What does it mean in your answer when you say, "you'll have to suppress the Content-type header?" Are you saying if you suppress that - then this won't appear in the logs? Or are you saying it is impossible? If it is possible, how? – Praxiteles Oct 01 '16 at 02:55
1

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
hirano
  • 106
  • 5