-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
response.iter_lines() did not print the last line of stream log. #3577
Comments
So You can get the effect you want by setting the chunk size to |
Thanks @Lukasa # curl --raw -v 'https://some-url.com'
< Transfer-Encoding: chunked
< Content-Type: text/plain; charset=utf-8
4f
2016-09-20T09:56:36 Welcome, you are now connected to log-streaming service.
37
PORT is:\\\\.\\pipe\\xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx
11
Something wrong
12
Something normal
# r.iter_content(hunk_size=None, decode_unicode=False)
b'2016-09-20T10:12:09 Welcome, you are now connected to log-streaming service.'
b'\r\nPORT is:\\\\.\\pipe\\xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx\r'
b'\nSomething normal'
b'\r\nSomething wrong\r'
b'\n'
b'PORT is:\\\\.\\pipe\\xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx\r\n'
b'Something wrong\r\nSomething '
b'normal\r\n'
b'PORT is:\\\\.\\pipe\\xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx\r\nSomething '
b'wrong\r\nSomething ' We can see that |
I didn't realise you were getting chunked content. In that case, can you try the latest Requests with |
I tried with v2.11 but saw the same issue. Does |
@haocs Only when using |
Even with
The above snippet shows two chunks that fetched by requests and curl from server. It seems that requests did not handle trailing CRLF(which is part of the chunk) properly. For example, chunk_size of the first chunk indicate the size is |
I don't observe this problem on Python when using Can you also confirm for me that you ran your test on v2.11? |
yes, I tested against v2.11.1. Requests works fine with |
mkcert.org provides a
Note that the |
I understand the end # python req_urllib3.py
[len of chunk] 0x4f
b'2016-09-23T19:27:27 Welcome, you are now connected to log-streaming service.\r\n'
[len of chunk] 0x39
b'2016-09-23T19:28:27 No new trace in the past 1 min(s).\r\n'
# python req_requests.py
[len of chunk] 0x4d
b'2016-09-23T19:25:09 Welcome, you are now connected to log-streaming service.'
[len of chunk] 0x39
b'\r\n2016-09-23T19:26:09 No new trace in the past 1 min(s).' |
Requests uses urllib3 directly and performs no additional post processing in this case. |
What's the urllib3 version shipped with requests v2.11? |
Ok, I could repro this "issue" with urllib3. If I use urllib3 and set |
So do you see the problem go away if you set |
Yes. After I set |
Ok. This strongly suggests that the problem is the way that the server is handling gzipping a chunked body. It would be very interesting if possible to see the raw data stream. |
Since I could observe same problem using curl or urllib3 with gzip enabled, obviously this not necessary to be an issue of requests. Thank you very much for the help, issue closed. |
I implemented the following function to fetch stream log from server continuously.
The above code could fetch and print the log successfully however its behavior was different as expected.
Basically, it holds the last line of current content/chunk and prints it together with the next chunk of logs.
For example, let's say there are two chunks of logs from server and the expected print:
what
stream_trace
function printed out('a' printed as 2nd chunk and 'c' was missing)Could you help me figure out what may went wrong? Thanks.
The text was updated successfully, but these errors were encountered: