Repository navigation
Closed
Description
I'm getting weird behavior when specifying headers on the command line.
Checklist
-
I've searched for similar issues.
-
I'm using the latest version of HTTPie.
- httpie v3.2.4
- Win11 Pro x64 24H2
- Python 3.10.0
Note that I'm new to httpie.
Minimal reproduction code and steps
Running the the example from https://httpie.io/docs/cli/http-headers (adding --offline so it outputs the request headers), the only header that shows up from those given on the command line is the Referer header. (I assume the rest are expected default headers):
C:\httpie>http --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar Referer:https://httpie.org/
GET /headers HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: pie.dev
Referer: https://httpie.org/ # only header from the command line
If I remove a header from the command line all the other headers show up:
C:\httpie>http --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar
GET /headers HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: valued-visitor=yes;foo=bar # printed now
Host: pie.dev
User-Agent: Bacon/1.0 # printed now
X-Foo: Bar # printed now
If instead of removing a header I add another ( X-Bar:Foo in this example), the problem changes to an error:
C:\httpie>http --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Bar:Foo X-Foo:Bar Referer:https://httpie.org/
http: error: KeyError: 'Referer'
Expected result
The headers on the command line get printed, no bogus errors
Debug output
C:\httpie>http --debug --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar Referer:https://httpie.org/
HTTPie 3.2.4
Requests 2.32.4
Pygments 2.19.2
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
C:\Python310\python.exe
Windows 10
<Environment {'apply_warnings_filter': <function Environment.apply_warnings_filter at 0x000001DDD0644A60>,
'args': Namespace(),
'as_silent': <function Environment.as_silent at 0x000001DDD0644940>,
'colors': 256,
'config': {'default_options': []},
'config_dir': WindowsPath('C:/Users/mburr/AppData/Roaming/httpie'),
'devnull': <property object at 0x000001DDD05E47C0>,
'is_windows': True,
'log_error': <function Environment.log_error at 0x000001DDD06449D0>,
'program_name': 'http',
'quiet': 0,
'rich_console': <functools.cached_property object at 0x000001DDD05CE440>,
'rich_error_console': <functools.cached_property object at 0x000001DDD05CF0D0>,
'show_displays': True,
'stderr': <colorama.ansitowin32.StreamWrapper object at 0x000001DDD05CDFC0>,
'stderr_isatty': True,
'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
'stdin_encoding': 'utf-8',
'stdin_isatty': True,
'stdout': <colorama.ansitowin32.StreamWrapper object at 0x000001DDD05CC2B0>,
'stdout_encoding': 'utf-8',
'stdout_isatty': True}>
<PluginManager {'adapters': [],
'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
<class 'httpie.plugins.builtin.DigestAuthPlugin'>,
<class 'httpie.plugins.builtin.BearerAuthPlugin'>],
'converters': [],
'formatters': [<class 'httpie.output.formatters.headers.HeadersFormatter'>,
<class 'httpie.output.formatters.json.JSONFormatter'>,
<class 'httpie.output.formatters.xml.XMLFormatter'>,
<class 'httpie.output.formatters.colors.ColorFormatter'>]}>
>>> requests.request(**{'auth': None,
'data': RequestJSONDataDict(),
'headers': <HTTPHeadersDict('User-Agent': b'Bacon/1.0', 'Cookie': b'valued-visitor=yes;foo=bar', 'X-Foo': b'Bar', 'Referer': b'https://httpie.org/')>,
'method': 'get',
'params': <generator object MultiValueOrderedDict.items at 0x000001DDD1432B90>,
'url': 'http://pie.dev/headers'})
GET /headers HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: pie.dev
Referer: https://httpie.org/
C:\httpie>http --debug --offline pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Bar:Foo X-Foo:Bar Referer:https://httpie.org/
HTTPie 3.2.4
Requests 2.32.4
Pygments 2.19.2
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
C:\Python310\python.exe
Windows 10
<Environment {'apply_warnings_filter': <function Environment.apply_warnings_filter at 0x000001F7282D4A60>,
'args': Namespace(),
'as_silent': <function Environment.as_silent at 0x000001F7282D4940>,
'colors': 256,
'config': {'default_options': []},
'config_dir': WindowsPath('C:/Users/mburr/AppData/Roaming/httpie'),
'devnull': <property object at 0x000001F728274720>,
'is_windows': True,
'log_error': <function Environment.log_error at 0x000001F7282D49D0>,
'program_name': 'http',
'quiet': 0,
'rich_console': <functools.cached_property object at 0x000001F72825E440>,
'rich_error_console': <functools.cached_property object at 0x000001F72825F0D0>,
'show_displays': True,
'stderr': <colorama.ansitowin32.StreamWrapper object at 0x000001F72825DFC0>,
'stderr_isatty': True,
'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
'stdin_encoding': 'utf-8',
'stdin_isatty': True,
'stdout': <colorama.ansitowin32.StreamWrapper object at 0x000001F72825C2B0>,
'stdout_encoding': 'utf-8',
'stdout_isatty': True}>
<PluginManager {'adapters': [],
'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
<class 'httpie.plugins.builtin.DigestAuthPlugin'>,
<class 'httpie.plugins.builtin.BearerAuthPlugin'>],
'converters': [],
'formatters': [<class 'httpie.output.formatters.headers.HeadersFormatter'>,
<class 'httpie.output.formatters.json.JSONFormatter'>,
<class 'httpie.output.formatters.xml.XMLFormatter'>,
<class 'httpie.output.formatters.colors.ColorFormatter'>]}>
>>> requests.request(**{'auth': None,
'data': RequestJSONDataDict(),
'headers': <HTTPHeadersDict('User-Agent': b'Bacon/1.0', 'Cookie': b'valued-visitor=yes;foo=bar', 'X-Bar': b'Foo', 'X-Foo': b'Bar', 'Referer': b'https://httpie.org/')>,
'method': 'get',
'params': <generator object MultiValueOrderedDict.items at 0x000001F7290B2B90>,
'url': 'http://pie.dev/headers'})
http: error: KeyError: 'Referer'
Traceback (most recent call last):
File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Python310\Scripts\http.exe\__main__.py", line 7, in <module>
File "C:\Python310\lib\site-packages\httpie\__main__.py", line 9, in main
exit_status = main()
File "C:\Python310\lib\site-packages\httpie\core.py", line 162, in main
return raw_main(
File "C:\Python310\lib\site-packages\httpie\core.py", line 140, in raw_main
handle_generic_error(e)
File "C:\Python310\lib\site-packages\httpie\core.py", line 100, in raw_main
exit_status = main_program(
File "C:\Python310\lib\site-packages\httpie\core.py", line 213, in program
for message in messages:
File "C:\Python310\lib\site-packages\httpie\client.py", line 93, in collect_messages
transform_headers(request, prepared_request)
File "C:\Python310\lib\site-packages\httpie\client.py", line 227, in transform_headers
apply_missing_repeated_headers(
File "C:\Python310\lib\site-packages\httpie\client.py", line 257, in apply_missing_repeated_headers
new_headers.popone(prepared_name)
KeyError: 'Referer'
Any help is appreciated.
Reacted by Kexin Xie
Activity
mburr commentedon Jun 23, 2025
This problem seems to have been introduced in httpie v3.0.0
I ran the examples from my original post on a Linux workstation with a python 3.13 virtual environment set up. httpie versions 3.2.4 and 3.0.0 behaved exactly like the Win11/Python 3.10.0 examples in my previous post.
httpie v2.6.0 works as expected.
httpie 2.6.0 on Linux with Python 3.13 virtual environment
(the warnings about pkg_resources can be ignored)
httpie 2.6.0 on Linux with Python 3.13 virtual environment with
--debugleemars commentedon Jun 23, 2025
The multidict library, a dependency of httpie/cli, released version 6.5.0 on 2025-06-17. This update introduced some internal implementation changes that have caused httpie/cli to stop working correctly. This issue is actually due to this problem with multidict 6.5.0. Downgrading to the previous version (6.4.4) resolves the issue.
[-]Problems specifying headers on command line[/-][+]multidict 6.5.0 causes problems specifying headers on command line[/+]mburr commentedon Jun 24, 2025
Indeed it does. Thank you!
I've edited the bug title to reflect that. I don't know enough about python packaging to submit a PR for fixing this on
pip install. I hope someone else will pick that up (or come up with a better solution). Maybe I'll try to muddle through and learn something along the way.mburr commentedon Jun 24, 2025
The bug in multidict 6.5.0 is fixed and will be released in multidict 6.5.1:
mburr commentedon Jun 24, 2025
The broken multidict 6.5.0 has been yanked from https://pypi.org/ so from here on pip will install multidict 6.4.4 (or 6.5.1 when it is released) instead of the broken 6.5.0.
A fresh install of httpie shows the correct behavior.
If you already have multidict 6.5.0, the following should fix things:
Amazing response from both the httpie and multidict communities.
Closed
benja-M-1 commentedon Jul 4, 2025
Hi, I am still facing the issue with httpie installed from brew on mac os. Would a republish on homebrew be needed?