requests icon indicating copy to clipboard operation
requests copied to clipboard

OrderedDict not working on headers again

Open alwaysnotworkingforme opened this issue 7 years ago • 4 comments

Summary. OrderedDict not working on headers again. I have tried both 2.21.0 and 2.18.4 It works fine on data but not working on headers, headers still get reordered.

Expected Result

headers01 = OrderedDict([("Connection", "close"), ("Upgrade-Insecure-Requests", "1"), ("User-Agent", "SomeAgent"), ("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8"), ("Accept-Encoding", "gzip, deflate"), ("Accept-Language", "Some Language")])

Actual Result

Connection: close Accept-Encoding: gzip, deflate Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8 User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; InfoPath.2) Accept-Language: en-US,en;q=0.5 Upgrade-Insecure-Requests: 1

Reproduction Steps

import requests

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "2.7.15"
  },
  "platform": {
    "release": "7",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "100020ff"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": false
}

BTW 

**AND I know there is no way to ask anyone to fix it since it's just a free project, and I do not Expected anyone to fix it.**
I just want someone to help me providing a requests **version number** which do not have this issue.
OrderedDict still works fine on data in this version.

dataxx = OrderedDict([("xxx", "xxx"), ("yyy", ''), ("zzz", ''), ("000", "222")])

alwaysnotworkingforme avatar Mar 06 '19 15:03 alwaysnotworkingforme

Yea I just noticed this myself... only affect py2... i have gone back to 2.10 even and its still doing it... py3 on 2.12.4 is keeping the order

VeNoMouS avatar Apr 09 '19 10:04 VeNoMouS

Referring back to here .. https://github.com/kennethreitz/requests/issues/2057

@alwaysnotworkingforme , if you setup a session first

session = requests.session() then do session.headers=OrderedDict() before you're get request the headers is defined as an OrderedDict and stays as such..

@kenneth-reitz

VeNoMouS avatar Apr 09 '19 10:04 VeNoMouS

@VeNoMouS - Thanks! This is exactly the solution I was looking for.

Confirmed this is working for requests version 2.22.0

jtoledo2 avatar Dec 11 '19 21:12 jtoledo2

Closing this issue as fixed.

sethmlarson avatar Nov 28 '21 03:11 sethmlarson