"Placing" arbitrary number of values into Python Flask request_context?
Question: So I have a Python Flask app such as the following: (it's actually a [Clay
Flask](https://pypi.python.org/pypi/clay-flask/1.1 "Clay Flask") app, but
whatever):

`some_file.py`:

    
    
    @app.route('/v1/some/route', methods=['GET'])
    def some_method():
        arg1 = request.args.get('arg1', None)
        arg2 = request.args.get('arg2', None)
        header1 = request.headers.get('header1', None)
        result = my_class.method_call(arg1, arg2, header1)
    

`my_class.py`:

    
    
    ...
    def method_call(self, arg1, arg2):
        # need to access header1 here
        some_other_service.make_request(arg1, arg2, header1)
    

The problem, is, I have a large number of headers, not just `header1`, that
`method_call` needs to know about in its call to
`some_other_service.make_request`. I could pass them all into `method_call`,
or create a wrapper object that has all of the headers as attributes, but have
been recommended to put the headers in the Flask/Clay `request_context`.

Here is where I'm stuck. I've read documentation on Flask and
request_contexts, but am still confused. How would I accomplish something like
this?


Answer: You can just use request in your Class.

    
    
    # from Flask import request
    
    def method_call(self, arg1, arg2):
        # need to access header1 here
        foo = request.headers.get('foo')
        bar = request.headers.get('bar')
        some_other_service.make_request(arg1, arg2, header1)
    

