Python Encode Spaces are incorrectly encoded
<p>I have a dictionary as follows </p>

<pre><code>params = {
        'response_type': 'token',
        'client_id': o_auth_client_id,
        'redirect_url': call_back_url,
        'scope': 'activity heartrate location'

}
print urllib.urlencode(params)
</code></pre>

<p>and um encoding it </p>

<p>but in results </p>

<blockquote>
  <p>redirect_url=http%3A%2F%2F127.0.0.1%3A8084%2Fagile_healtg%2Faccess_token%2F&amp;response_type=token&amp;client_id=xxxxxx&amp;scope=activity+heartrate+location</p>
</blockquote>

<p>um getting something like above 
Unfortunately spaces are encoded as + signs </p>

<p>but the results should be </p>

<blockquote>
  <p>scope=activity%20nutrition%20heartrate</p>
</blockquote>

<p>how may I achieve the correct encode for spaces in python ?</p>

<p>This program might do what you ask for. </p>

<pre><code>import urllib

def my_special_urlencode(params):
    return '&amp;'.join('{}={}'.format(urllib.quote(k, ''), urllib.quote(v, '')) for k,v in params.items())

params = {
        'response_type': 'token',
        'client_id': 'xxxxxx',
        'redirect_url': 'http://example.com/callback',
        'scope': 'activity heartrate location'

}

print my_special_urlencode(params)
</code></pre>

<p>Result:</p>

<pre><code>redirect_url=http%3A%2F%2Fexample.com%2Fcallback&amp;response_type=token&amp;client_id=xxxxxx&amp;scope=activity%20heartrate%20location
</code></pre>

python encoding urlencode