I need to iterate over all request header objects and print it in App Engine. I get error when trying to use for cycle. How to do that correctly?
class MainHandler(webapp.RequestHandler):
def get(self):
for e in self.request.headers:
self.request.headers(e + "<br />")
I get error: AttributeError: EnvironHeaders instance has no __call__ method
Error is in self.request.headers(e + "<br />")
line. You are trying to call the request.headers
method.
I check the online help and found that self.request.headers
is dict
like object. You can check in https://developers.google.com/appengine/docs/python/gettingstarted/usingwebapp
To iterate over the headers
you can use self.request.headers.items()
or self.request.headers.keys()
I think you mean self.response.write()
:
class MainHandler(webapp.RequestHandler):
def get(self):
for e in self.request.headers:
self.response.write(e + "<br />")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With