Python post request with Bearer token : <p>Im trying to make a script that post data on REST service together with Bearer token. </p>

<p>Here is working PHP example:</p>

<pre><code>$postData = array( 'app' =&gt; 'aaaa' );

$ch = curl_init($apiUrl);
curl_setopt_array($ch, array(
    CURLOPT_HTTPHEADER, ['Authorization: Bearer '.$accessToken],
    CURLOPT_POST =&gt; TRUE,
    CURLOPT_RETURNTRANSFER =&gt; TRUE,
    CURLOPT_POSTFIELDS =&gt; json_encode($postData)
));

$response = curl_exec($ch);
</code></pre>

<p>Im trying to do the same with python. Here is what i got so far...</p>

<pre><code>import urllib2, urllib
import json

auth_token='kbkcmbkcmbkcbc9ic9vixc9vixc9v'
hed = {'Authorization': 'Bearer ' + auth_token}
data = urllib.urlencode({'app' : 'aaaaa'})

url = 'https://api.xy.com'
req = urllib2.Request(url=url, headers=hed, data=data)
content = urllib2.urlopen(req).read()
print content
</code></pre>

<p>I get HTTP Error 400: Bad Request. 
Any help appretiated...</p>
