Include multiple headers in python requests
<p>I have this HTTPS call in curl below;</p>

<pre><code>header1="projectName: zhikovapp"
header2="Authorization: Bearer HZCdsf="
bl_url="https://BlazerNpymh.com/api/documents?pdfDate=$today"

curl -s -k -H "$header1" -H "$header2" "$bl_url" 
</code></pre>

<p>I would like to write an equivalent python call using requests module.</p>

<pre><code>header ={
            "projectName": "zhikovapp",
            "Authorization": "Bearer HZCdsf="
        }
response = requests.get(bl_url, headers = header)
</code></pre>

<p>However, the request was not valid. What is wrong?</p>

<p>The contents of the returned response is like this;</p>

<pre><code>&lt;Response [400]&gt;
_content = '{"Message":"The request is invalid."}'
headers = {'Content-Length': '37', 'Access-Control-Allow-Headers': 'projectname, authorization, Content-Type', 'Expires': '-1', 'cacheControlHeader': 'max-age=604800', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache', 'Date': 'Sat, 15 Oct 2016 02:41:13 GMT', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', 'Content-Type': 'application/json; charset=utf-8'}
reason = 'Bad Request'
</code></pre>

<p>I am using python 2.7</p>

<p>EDIT: I corrected some syntex errors after Soviut pointed them out.</p>

<p>In <code>request.get()</code> the <a href="http://docs.python-requests.org/en/master/user/quickstart/#custom-headers" rel="nofollow"><code>headers</code></a> argument should be defined as a dictionary, a set of key/value pairs. You've defined a set (a unique list) of strings instead.</p>

<p>You should declare your headers like this:</p>

<pre><code>headers = {
    "projectName": "zhikovapp",
    "Authorization": "Bearer HZCdsf="
}
response = requests.get(bl_url, headers=headers)
</code></pre>

<p>Note the <code>"key": "value"</code> format of each line inside the dictionary.</p>

python python-2.7 curl python-requests