Skip to content

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

@tuhaolam

Description

@tuhaolam

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions