Translate cURL headers command to python-requests
<p>I need to pass a POST containing a token to a website to get an auth key, I've done it successfully using cURL with this statement:</p>

<p><code>curl -D - --request POST https://login.website.com/g/aaa/authorize --data-urlencode token=[TOKEN]
</code></p>

<p>However, I cannot seem to get the same outcome using the Python requests module:</p>

<p><code>auth_token = requests.post('https://login.website.com/g/aaa/authorize', data=token)</code></p>

<p><code>auth_token.text</code> just gives me <code>'Unauthorized'</code></p>

<p>I've tried passing the data kawrg as :</p>

<ul>
<li>straight JSON </li>
<li>a string</li>
<li>adding <code>token=</code> to the beginning of the string</li>
<li>using <code>params</code> instead of data and passing it JSON (this gets me <code>unexpected argument: {"token" : "value....."}</code>)</li>
</ul>

<p>What is the significance of <code>-D</code> and <code>--data-urlencode</code> (as opposed to just <code>--data</code>) in this case, should I be trying to dump a header as an argument into the <code>requests.post()</code>?</p>

<p><em>ÐDIT:</em>
In the cURL output, the auth_key also is printed before any of the json starts:</p>

<pre><code>Set-Cookie: auth_key=[auth_key]; Domain=.website.com; expires=Fri, 30-Sep-2016 01:41:09 GMT; httponly; Max-Age=14399; Path=/
</code></pre>

<p>Found the answer, <code>requests.json()</code> needed to be used instead of <code>json.dumps(data)</code>, the latter is improperly formatted, so this code worked out fine:</p>

<pre><code>s.token = requests.post(url, data=data)
s.recieved = s.token.json()
t = requests.post(url, data=s.recieved)
</code></pre>

python curl python-requests