Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session file with cookie cannot be parsed #1126

Closed
caofanCPU opened this issue Aug 12, 2021 · 6 comments · Fixed by #1127
Closed

Session file with cookie cannot be parsed #1126

caofanCPU opened this issue Aug 12, 2021 · 6 comments · Fixed by #1127
Assignees
Labels
bug Something isn't working new Needs triage. Comments are welcome!

Comments

@caofanCPU
Copy link

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?

@caofanCPU caofanCPU added bug Something isn't working new Needs triage. Comments are welcome! labels Aug 12, 2021
@BoboTiG
Copy link
Contributor

BoboTiG commented Aug 13, 2021

Could you rerun the command with --debug and copy-paste the whole output (not a screenshot)?
Also, remove the >>~/Desktop/result.json part to have the output displayed in the terminal.

@BoboTiG
Copy link
Contributor

BoboTiG commented Aug 13, 2021

What is the content of query.json?

@caofanCPU
Copy link
Author

caofanCPU commented Aug 13, 2021

@BoboTiG
Just a normal json data like this:

{
  "data": {
    
  },
  "pageNum": 1,
  "pageSize": 100
}

@caofanCPU
Copy link
Author

caofanCPU commented 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.

@BoboTiG BoboTiG self-assigned this Aug 13, 2021
@BoboTiG
Copy link
Contributor

BoboTiG commented Aug 13, 2021

Thank you @caofanCPU. I can reproduce the problem, expect a fix very soon :)

@caofanCPU
Copy link
Author

@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! 🤝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new Needs triage. Comments are welcome!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants