Keeping order of parameters in Python Post Request
<p>For some reason, I need to influence the ordering of the data in post-Request with the requests-library.</p>

<p>Consider this:</p>

<pre><code>data = {
    'param1': "foo",
    'param2': "bar",
}

print requests.post(url, data=data) 
</code></pre>

<p>So param1 should be in the body before param2. A corresponding curl-Request would look like that:</p>

<pre><code>curl --data "param1=foo&amp;param2=bar" https://url.com
</code></pre>

<p>However, a dict is unordered in Python, so the actual ordering may differ. Is there a way to tell the request-library, in which order the parameters should be sent? Maybe to give the parameters urlencoded?</p>

<p>You can use an <a href="https://docs.python.org/2/library/collections.html#collections.OrderedDict" rel="nofollow"><code>OrderedDict</code></a> instead:</p>

<pre><code>from collections import OrderedDict

data = OrderedDict(param1="foo", param2="bar")
print requests.post(url, data=data)
</code></pre>

python post request