Skip to content

multidict 6.5.0 causes problems specifying headers on command line #1637

Closed

Description

@mburr

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.

Activity

  1. added
    bug
    new
    on Jun 23, 2025
  2. mburr commented on Jun 23, 2025

    @mburr
    Author

    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)

    (.venv) mburr@burrvm-mint20:~$ http --version
    /home/mburr/.venv/lib/python3.13/site-packages/httpie/plugins/manager.py:5: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
      from pkg_resources import iter_entry_points
    
    2.6.0
    
    (.venv) mburr@burrvm-mint20:~$ http --offline  pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar  Referer:https://httpie.org/
    /home/mburr/.venv/lib/python3.13/site-packages/httpie/plugins/manager.py:5: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
      from pkg_resources import iter_entry_points
    GET /headers HTTP/1.1
    Accept: */*
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Cookie: valued-visitor=yes;foo=bar
    Host: pie.dev
    Referer: https://httpie.org/
    User-Agent: Bacon/1.0
    X-Foo: Bar
    
    (.venv) mburr@burrvm-mint20:~$ http --offline  pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar  X-Bar:Foo Referer:https://httpie.org/
    /home/mburr/.venv/lib/python3.13/site-packages/httpie/plugins/manager.py:5: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
      from pkg_resources import iter_entry_points
    GET /headers HTTP/1.1
    Accept: */*
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Cookie: valued-visitor=yes;foo=bar
    Host: pie.dev
    Referer: https://httpie.org/
    User-Agent: Bacon/1.0
    X-Bar: Foo
    X-Foo: Bar
    

    httpie 2.6.0 on Linux with Python 3.13 virtual environment with --debug

    (.venv) mburr@burrvm-mint20:~$ http --debug --offline  pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar  Referer:https://httpie.org/
    /home/mburr/.venv/lib/python3.13/site-packages/httpie/plugins/manager.py:5: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
      from pkg_resources import iter_entry_points
    HTTPie 2.6.0
    Requests 2.32.4
    Pygments 2.19.2
    Python 3.13.5 (main, Jun 12 2025, 08:56:14) [GCC 9.4.0]
    /home/mburr/.venv/bin/python3.13
    Linux 5.4.0-200-generic
    
    <Environment {'colors': 256,
     'config': {'__meta__': {'about': 'HTTPie configuration file',
                             'help': 'https://httpie.org/doc#config',
                             'httpie': '1.0.3'},
                'default_options': []},
     'config_dir': PosixPath('/home/mburr/.httpie'),
     'devnull': <property object at 0x7fcd3122b740>,
     'is_windows': False,
     'log_error': <function Environment.log_error at 0x7fcd3120e7a0>,
     'program_name': 'http',
     'stderr': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>,
     'stderr_isatty': True,
     'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
     'stdin_encoding': 'utf-8',
     'stdin_isatty': True,
     'stdout': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>,
     'stdout_encoding': 'utf-8',
     'stdout_isatty': True}>
    
    <PluginManager {'adapters': [],
     'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
              <class 'httpie.plugins.builtin.DigestAuthPlugin'>],
     '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': {'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 0x7fcd312e7e20>,
     'url': 'http://pie.dev/headers'})
    
    GET /headers HTTP/1.1
    Accept: */*
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Cookie: valued-visitor=yes;foo=bar
    Host: pie.dev
    Referer: https://httpie.org/
    User-Agent: Bacon/1.0
    X-Foo: Bar
    
    (.venv) mburr@burrvm-mint20:~$ http --debug --offline  pie.dev/headers User-Agent:Bacon/1.0 "Cookie:valued-visitor=yes;foo=bar" X-Foo:Bar  X-Bar:Foo Referer:https://httpie.org/
    /home/mburr/.venv/lib/python3.13/site-packages/httpie/plugins/manager.py:5: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
      from pkg_resources import iter_entry_points
    HTTPie 2.6.0
    Requests 2.32.4
    Pygments 2.19.2
    Python 3.13.5 (main, Jun 12 2025, 08:56:14) [GCC 9.4.0]
    /home/mburr/.venv/bin/python3.13
    Linux 5.4.0-200-generic
    
    <Environment {'colors': 256,
     'config': {'__meta__': {'about': 'HTTPie configuration file',
                             'help': 'https://httpie.org/doc#config',
                             'httpie': '1.0.3'},
                'default_options': []},
     'config_dir': PosixPath('/home/mburr/.httpie'),
     'devnull': <property object at 0x7feea683f7e0>,
     'is_windows': False,
     'log_error': <function Environment.log_error at 0x7feea68227a0>,
     'program_name': 'http',
     'stderr': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>,
     'stderr_isatty': True,
     'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
     'stdin_encoding': 'utf-8',
     'stdin_isatty': True,
     'stdout': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>,
     'stdout_encoding': 'utf-8',
     'stdout_isatty': True}>
    
    <PluginManager {'adapters': [],
     'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
              <class 'httpie.plugins.builtin.DigestAuthPlugin'>],
     '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': {'User-Agent': b'Bacon/1.0', 'Cookie': b'valued-visitor=yes;foo=bar', 'X-Foo': b'Bar', 'X-Bar': b'Foo', 'Referer': b'https://httpie.org/'},
     'method': 'get',
     'params': <generator object MultiValueOrderedDict.items at 0x7feea68fbe20>,
     'url': 'http://pie.dev/headers'})
    
    GET /headers HTTP/1.1
    Accept: */*
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    Cookie: valued-visitor=yes;foo=bar
    Host: pie.dev
    Referer: https://httpie.org/
    User-Agent: Bacon/1.0
    X-Bar: Foo
    X-Foo: Bar
    
  3. leemars commented on Jun 23, 2025

    @leemars

    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.

  4. changed the title [-]Problems specifying headers on command line[/-] [+]multidict 6.5.0 causes problems specifying headers on command line[/+] on Jun 24, 2025
  5. mburr commented on Jun 24, 2025

    @mburr
    Author

    Downgrading [multidict] to the previous version (6.4.4) resolves the issue.

    Indeed it does. Thank you!

    pip uninstall multidict
    pip install "multidict==6.4.*"
    

    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.

  6. mburr commented on Jun 24, 2025

    @mburr
    Author

    The bug in multidict 6.5.0 is fixed and will be released in multidict 6.5.1:

  7. mburr commented on Jun 24, 2025

    @mburr
    Author

    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:

    pip uninstall multidict
    pip cache purge
    pip install httpie
    

    Amazing response from both the httpie and multidict communities.

    Closed

  8. benja-M-1 commented on Jul 4, 2025

    @benja-M-1

    Hi, I am still facing the issue with httpie installed from brew on mac os. Would a republish on homebrew be needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnew

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions