question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Session file with cookie cannot be parsed

See original GitHub issue

Checklist

  • [Y] I’ve searched for similar issues.

  • [Y] I’m using the the latest version of HTTPie.

  • httpie version, 2.4.0

  • python version, 3.9

I prepared the my-session-cookie.json file, the request parameters are placed in query.json, and the expected response results are placed in the result.json file.

my-session-cookie.json like this: { "__meta__": { "about": "HTTPie session file", "help": "https://httpie.org/doc#sessions", "httpie": "2.4.0" }, "headers": { "Content-Type": "application/json", "cookie": "12345" } }

And command like this: 2021813-22044 Xnip2021-08-13_02-22-22

http --verify=no -v --session-read-only=~/Desktop/my-session-cookie.json POST http://localhost:8301/test < ~/Desktop/query.json -d >>~/Desktop/result.json

And I got error like this: http: error: RuntimeError: OrderedDict mutated during iteration

Then I did some test and the request can be executed

  • remove cookie field
  • OR remove -d >>~/Desktop/result.json in the command

So what’s wrong?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
caofanCPUcommented, Aug 17, 2021

@BoboTiG @jokull Thank you for your timely handling work, my httpie util is online again, ✌️! ‘cause can’t wait for the release version, I directly install the latest versio from the master. 😎 Of course, I am looking forward to the next release version! 🤝

1reaction
caofanCPUcommented, Aug 13, 2021

Sry, I missed this msg. In debug mode:

CASE 1:

http --debug  --verify=no -v  --session-read-only=~/Desktop/my-session-cookie.json POST http://localhost:8301/test < ~/Desktop/query.json -d >>~/Desktop/result.json`

HTTPie 2.4.0
Requests 2.25.1
Pygments 2.7.4
Python 3.9.5 (default, May  4 2021, 03:33:11)
[Clang 12.0.0 (clang-1200.0.32.29)]
/usr/local/Cellar/httpie/2.4.0/libexec/bin/python3.9
Darwin 19.6.0

<Environment {'colors': 256,
 'config': {'default_options': []},
 'config_dir': PosixPath('/Users/bytedance/.config/httpie'),
 'devnull': <property object at 0x1025e11d0>,
 'is_windows': False,
 'log_error': <function Environment.log_error at 0x1025dde50>,
 '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': False,
 'stdout': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>,
 'stdout_encoding': 'utf-8',
 'stdout_isatty': False}>

**http: error: RuntimeError: OrderedDict mutated during iteration**

Traceback (most recent call last):
  File "/usr/local/bin/http", line 33, in <module>
    sys.exit(load_entry_point('httpie==2.4.0', 'console_scripts', 'http')())
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/httpie/__main__.py", line 11, in main
    exit_status = main()
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/httpie/core.py", line 70, in main
    exit_status = program(
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/httpie/core.py", line 169, in program
    for message in messages:
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/httpie/client.py", line 63, in collect_messages
    httpie_session.update_headers(request_kwargs['headers'])
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/httpie/sessions.py", line 75, in update_headers
    for name, value in request_headers.items():
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_collections_abc.py", line 849, in __iter__
    for key in self._mapping:
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/requests/structures.py", line 60, in <genexpr>
    return (casedkey for casedkey, mappedvalue in self._store.values())
RuntimeError: OrderedDict mutated during iteration

CASE 2:

http --debug  --verify=no -v  --session-read-only=~/Desktop/my-session-cookie.json POST http://localhost:8301/test < ~/Desktop/query.json`

HTTPie 2.4.0
Requests 2.25.1
Pygments 2.7.4
Python 3.9.5 (default, May  4 2021, 03:33:11)
[Clang 12.0.0 (clang-1200.0.32.29)]
/usr/local/Cellar/httpie/2.4.0/libexec/bin/python3.9
Darwin 19.6.0

<Environment {'colors': 256,
 'config': {'default_options': []},
 'config_dir': PosixPath('/Users/bytedance/.config/httpie'),
 'devnull': <property object at 0x10d88f130>,
 'is_windows': False,
 'log_error': <function Environment.log_error at 0x10d888e50>,
 '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': False,
 'stdout': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>,
 'stdout_encoding': 'utf-8',
 'stdout_isatty': True}>

>>> requests.request(**{'auth': None,
 'data': <_io.BufferedReader name='<stdin>'>,
 'headers': {'User-Agent': b'HTTPie/2.4.0', 'Accept': b'application/json, */*;q=0.5', 'Content-Type': b'application/json'},
 'method': 'post',
 'params': <generator object MultiValueOrderedDict.items at 0x10d93ee40>,
 'url': 'http://localhost:8301/test'})

POST /test HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 60
Content-Type: application/json
Host: localhost:8301
User-Agent: HTTPie/2.4.0


http: error: ConnectionError: HTTPConnectionPool(host='localhost', port=8301): Max retries exceeded with url: /test (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10d9c01f0>: Failed to establish a new connection: [Errno 61] Connection refused')) while doing a POST request to URL: http://localhost:8301/test

Traceback (most recent call last):
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/util/connection.py", line 96, in create_connection
    raise err
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/util/connection.py", line 86, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1253, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1299, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1248, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1008, in _send_output
    self.send(msg)
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 948, in send
    self.connect()
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/connection.py", line 200, in connect
    conn = self._new_conn()
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/connection.py", line 181, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x10d9c01f0>: Failed to establish a new connection: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/urllib3/util/retry.py", line 573, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8301): Max retries exceeded with url: /test (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10d9c01f0>: Failed to establish a new connection: [Errno 61] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/http", line 33, in <module>
    sys.exit(load_entry_point('httpie==2.4.0', 'console_scripts', 'http')())
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/httpie/__main__.py", line 11, in main
    exit_status = main()
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/httpie/core.py", line 70, in main
    exit_status = program(
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/httpie/core.py", line 169, in program
    for message in messages:
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/httpie/client.py", line 101, in collect_messages
    response = requests_session.send(
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/Cellar/httpie/2.4.0/libexec/lib/python3.9/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8301): Max retries exceeded with url: /test (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10d9c01f0>: Failed to establish a new connection: [Errno 61] Connection refused'))

Case 1, http: error: RuntimeError: OrderedDict mutated during iteration CASE 2, can parse session file and can send http request

I wonder, sending a request with a cookie and writing the response to a specified file be supported at the same time? I remember that older versions, such as version 2.0.0, are supported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Websocket Handshake - cookie can't be parsed?
Yes, the cookie header only contains session=foobar; scrt=foomart . But then HttpCookie.parse() doesn't work correct, does it? – Lama. May ...
Read more >
Cookies, document.cookie - The Modern JavaScript Tutorial
A write operation to document.cookie updates only cookies mentioned in it, but doesn't touch other cookies. For instance, this call sets a ...
Read more >
Failed to parse the user's info from the token in the cookie.
I am trying to use the java sdk to parse the token in the cookie after SSO login successfully. ... You cannot parse...
Read more >
Express cookie-parser middleware
Parse a cookie value as a signed cookie. This will return the parsed unsigned value if it was a signed cookie and the...
Read more >
Understanding Cookies and Implementing them in Node.js
A cookie is usually a tiny text file stored in your web browser. ... Session cookies - store user's information for a short...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found