python request payload without sorting
<p>I am trying to use python request module to pass few values to server using the following code, but in the http request its changing the order of the payload values.   </p>

<pre><code>payload3 = {'OSILA_LinkTo_Site': OSILA_LinkTo_Site, 'OSILA_LinkTo_Service': OSILA_LinkTo_Service, 'OSILA_Locale': OSILA_Locale, 'OSILA_Locale_display': OSILA_Locale, 'OSILA_TimeZone': OSILA_TimeZone, 'OSILA_TimeZone_display': OSILA_TimeZone, 'selectedUser': '', 'OSILA_LinkTo_User_display': '', 'OSILA_LinkTo_User': OSILA_LinkTo_User, 'OSILA_DisplayName': OSILA_DisplayName, 'OSILA_CountryCode': OSILA_CountryCode, 'OSILA_AreaCode': OSILA_AreaCode, 'OSILA_LocalOfficeCode': OSILA_LocalOfficeCode, 'OSILA_LinkTo_Extension': OSILA_LinkTo_Extension, 'OSILA_ProductPackage': OSILA_ProductPackage, 'OSILA_ProductPackage_display': OSILA_ProductPackage, 'OSILA_DeviceType': OSILA_DeviceType, 'OSILA_DeviceType_display': OSILA_DeviceType, 'OSILA_Parameter_4': OSILA_Parameter_4, 'OSILA_Parameter_4_display': OSILA_Parameter_4, 'OSILA_Parameter_3': OSILA_Parameter_3, 'OSILA_Parameter_3_display': OSILA_Parameter_3, 'OSILA_Parameter_2': OSILA_Parameter_2, 'OSILA_Parameter_2_display': OSILA_Parameter_2, 'OSILA_Parameter_5': OSILA_Parameter_5, 'OSILA_Parameter_5_display': OSILA_Parameter_5, 'OSILA_Parameter_1': OSILA_Parameter_1, 'OSILA_Parameter_1_display': OSILA_Parameter_1, 'OSILA_CreateNewFax': OSILA_CreateNewFax, 'OSILA_LinkTo_ServiceFax': '', 'OSILA_CountryCodeFax': '', 'OSILA_AreaCodeFax': '', 'OSILA_LocalOfficeCodeFax': '', 'OSILA_LinkTo_ExtensionFax': '', 'OSILA_ProvisioningDate': OSILA_ProvisioningDate, 'OSILA_DateMail_1': OSILA_ProvisioningDate, 'OSILA_DateMail_2': '', 'OSILA_DateMail_3': '', 'OSILA_DateMail_4': '', 'OSILA_DateMail_5': '', 'OSILA_DateMail_6': '', 'OSILA_DateMail_7': '', 'OSILA_DateMail_8': '', 'OSILA_DateMail_9': '', 'attachEventListeners': '', 'webMgrRequestId': webMgrRequestId, 'WT': WT2, 'enterConfirm': 'true', 'users_R_0_C__select': 'on', 'selectedUser': '0'}
</code></pre>

<p><code>subcr = session.post("http://192.168.0.10:8080/OSILAManager/createSubscriber2.do", data=payload3)</code></p>

<p>using  browser i can see the values are passing in the following order ,but when i use python its changing the order, is there any way to avoid this sorting </p>

<pre><code>OSILA_LinkTo_Site
OSILA_LinkTo_Service
OSILA_Locale
OSILA_Locale_display
OSILA_TimeZone
OSILA_TimeZone_display
users_R_0_C__select
selectedUser
OSILA_LinkTo_User_display
OSILA_LinkTo_User
OSILA_DisplayName
OSILA_CountryCode
OSILA_AreaCode
OSILA_LocalOfficeCode
OSILA_LinkTo_Extension
OSILA_ProductPackage
OSILA_ProductPackage_display
OSILA_DeviceType
OSILA_DeviceType_display
OSILA_Parameter_4
OSILA_Parameter_4_display
OSILA_Parameter_3
OSILA_Parameter_3_display
OSILA_Parameter_2
OSILA_Parameter_2_display
OSILA_Parameter_5
OSILA_Parameter_5_display
OSILA_Parameter_1
OSILA_Parameter_1_display
OSILA_CreateNewFax
OSILA_LinkTo_ServiceFax
OSILA_CountryCodeFax
OSILA_AreaCodeFax
OSILA_LocalOfficeCodeFax
OSILA_LinkTo_ExtensionFax
OSILA_ProvisioningDate
OSILA_DateMail_1
OSILA_DateMail_2
OSILA_DateMail_3
OSILA_DateMail_4
OSILA_DateMail_5
OSILA_DateMail_6
OSILA_DateMail_7
OSILA_DateMail_8
OSILA_DateMail_9
attachEventListeners
webMgrRequestId
WT
enterConfirm
</code></pre>

<p>You can pass tuples in place of the dict:</p>

<pre><code>In [7]: 
   ...: import requests
   ...: d = {"foo":"bar","bar":"foo","123":"456"}
   ...: t = (("foo","bar"),("bar","foo"),("123","456"))
   ...: r1 = requests.post("http://httpbin.org", data=d)
   ...: r2 = requests.post("http://httpbin.org", data=t)
   ...: print(r1.request.body)
   ...: print(r2.request.body)
   ...: 
bar=foo&amp;123=456&amp;foo=bar
foo=bar&amp;bar=foo&amp;123=456
</code></pre>

<p>Also you have <code>selectedUser</code> twice in your <em>dict</em> so that won't work as you will only have the last key/value pair you assign, not sure what the correct format is but again tuples would allow you to repeat a key:</p>

<pre><code>In [8]: import requests
   ...: d = {"foo":"bar","bar":"foo","123":"456","selectedUser":"0", "selectedUs
   ...: er":"1"}
   ...: t = (("foo","bar"),("bar","foo"),("123","456"), ("selectedUser","0"),("s
   ...: electedUser","1"))
   ...: r1 = requests.post("http://httpbin.org", data=d)
   ...: r2 = requests.post("http://httpbin.org", data=t)
   ...: print(r1.request.body)
   ...: print(r2.request.body)
   ...: 
bar=foo&amp;selectedUser=1&amp;123=456&amp;foo=bar
foo=bar&amp;bar=foo&amp;123=456&amp;selectedUser=0&amp;selectedUser=1
</code></pre>

<p>You can see using a dict leaves you with just <code>selectedUser=1</code> as that is the last of the pair assigned. That may actually be your problem more than the order of the post body keys. If you only meant to use <code>selectedUser</code> once then remove whichever you did not mean to post.</p>

python python-requests unify