6

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

2 Answers 2

9

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()

Sign up to request clarification or add additional context in comments.

Comments

3

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 />")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.