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

how to parse single response when setting stream=True in map function? #175

Open
tuhaolam opened this issue Apr 29, 2024 · 0 comments
Open

Comments

@tuhaolam
Copy link

It seems that not response come back.

  • request code
    resp3 = grequests.map(rs3, stream=True)
    for response in resp3:
        for line in response.iter_lines():
            if line:
                event = json.loads(re.sub("^data: ", "", line.decode("utf-8")))
                if event["msg"] == "process_completed":
                    answer = event["output"]["data"][0][1][1]
                    print("pong")
                    result.append({"answer": answer})
  • request result
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "grequests_test.py", line 111, in <module>
    results = grequests_main(data)
  File "grequests_test.py", line 101, in grequests_main
    result = [{"answer": res.json()} for res in resp3]
  File "grequests_test.py", line 101, in <listcomp>
    result = [{"answer": res.json()} for res in resp3]
  File "/anaconda3/lib/python3.8/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/anaconda3/lib/python3.8/site-packages/requests/models.py", line 923, in text
    if not self.content:
  File "/anaconda3/lib/python3.8/site-packages/requests/models.py", line 899, in content
    self._content = b"".join(self.iter_content(CONTENT_CHUNK_SIZE)) or b""
  File "/anaconda3/lib/python3.8/site-packages/requests/models.py", line 818, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: InvalidChunkLength(got length b'', 0 bytes read)", InvalidChunkLength(got length b'', 0 bytes read))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant