title: Why am I unable to send HTTP Headers to Flask-RESTful reqparse module using add_argument()?
body: <p>I am trying to integrate the Flask-RESTful's request parsing interface, <a href="http://flask-restful-cn.readthedocs.io/en/0.3.4/reqparse.html" rel="nofollow">reqparse</a> in my backend to request HTTP headers from the client. Currently, I wish to use this for authentication of a user and wish to pass <code>'secret_key'</code> in HTTP headers.</p>
  
  <p>The function I am using for this task is the <code>add_argument()</code> function. My code for requesting the header is as follows:</p>
  
  <pre><code>reqparse = reqparse.RequestParser()
  reqparse.add_argument('secret_key', type=str, location='headers', required=True)
  </code></pre>
  
  <p>However, on sending the following cURL request:</p>
  
  <pre><code>curl -H "Content-Type: application/json" -H "{secret_key: SECRET}" -X POST -d '{}' http://localhost:5000/authUser
  </code></pre>
  
  <p>I recieve the following 400 error on my Pycharm Community edition editor :</p>
  
  <pre><code>127.0.0.1 - - [02/Aug/2016 18:48:59] "POST /authUser HTTP/1.1" 400 -
  </code></pre>
  
  <p>and the following message on my cURL terminal:</p>
  
  <pre><code>{
    "message": {
      "secret_key": "Missing required parameter in the HTTP headers"
    }
  }
  </code></pre>
  
  <p>To reproduce this error on Pycharm (and hopefully all other compilers as well), please use the files written below as follows:</p>
  
  <pre><code>Folder - Sample_App
      - __init__.py
      - run.py
      - views.py
  </code></pre>
  
  <p><strong>__init__.py</strong></p>
  
  <pre><code>from flask import Flask
  from flask_restful import Api
  from views import AuthUser
  
  app = Flask(__name__)
  
  api = Api(app)
  api.add_resource(AuthUser, '/authUser')
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from flask_restful import reqparse, Resource
  
  class AuthUser(Resource):
  
      def __init__(self):
          self.reqparse = reqparse.RequestParser()
          self.reqparse.add_argument('secret_key', type=str, location='headers', required=True)
  
      def post(self):
          data = self.reqparse.parse_args()
          if data['secret_key'] == "SECRET":
              print("Success")
              return 200
          return 400
  </code></pre>
  
  <p><strong>run.py</strong></p>
  
  <pre><code>from __init__ import app
  
  app.run(host='0.0.0.0', port=5000, debug=True)
  </code></pre>
  
  <p>Could you please tell me how to fix this issue? I want to know if the <code>location</code> parameter needs to be changed or if there is something wrong in my cURL request. </p>
  
  <p>EDIT: </p>
  
  <p>With the help of Methika's response, I have figured out the error. The <code>add_argument()</code> function does not take <code>_</code> in a headers parameter. However, when I use the <code>requests.headers['secret_key']</code> function, I am able to request headers with the <code>_</code> character just fine. Why is that the case?
  <br><br>
  New Code of <strong>views.py</strong>:</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>from flask_restful import reqparse, Resource
  
  class AuthUser(Resource):
  
      def __init__(self):
          self.reqparse = reqparse.RequestParser()
  
      def post(self):
          data = self.reqparse.parse_args()
          data['secret_key'] = request.headers['secret_key']
          if data['secret_key'] == "SECRET":
              print("Success")
              return 200
          return 400
  </code></pre>