requests.get(stream=True) will get incomplete data

when I use stream=True, I get these:
```python
#print response.headers['Content-Length']
1332224
#print response.raw.tell()
1332224
#print len(response.content)
1331968
```
the content I get is incomplete.But when I use stream=False,I can get complete data.
when I set `stream=True` and `response.iter_content(chunk_size=1024*32)` I also get incomplete data.


## Reproduction Steps

```python
import requests

r = request.get(url='http://down.ziyuanku.com/201708091545/b5e3765e0be509c91617da128ecf169f/Resources/ChuZhong/2017-07-12/cccee17addb349cf8966161180c3e3ea.doc', stream=True)
with open(file, 'wb') as f: 
    for chunk in r.iter_content(chunk_size=1024*36):
        if chunk:
            f.write(chunk)
            f.flush()
r.close()
```

## System Information

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.4"
  }, 
  "cryptography": {
    "version": ""
  }, 
  "implementation": {
    "name": "CPython", 
    "version": "2.7.10"
  }, 
  "platform": {
    "release": "16.7.0", 
    "system": "Darwin"
  }, 
  "pyOpenSSL": {
    "openssl_version": "", 
    "version": null
  }, 
  "requests": {
    "version": "2.18.1"
  }, 
  "system_ssl": {
    "version": "9081df"
  }, 
  "urllib3": {
    "version": "1.21.1"
  }, 
  "using_pyopenssl": false
}
```

The only change in behaviour from `stream=True` to `stream=False` is changing where in the code-path we consume the body. It causes no externally visible effects, nor does it affect the way we load the code. Do you know for a fact that the body is corrupted in this case?

```python
#this is the property of response in requests/models.py
 @property
    def content(self):
        """Content of the response, in bytes."""

        if self._content is False:

            if self._content_consumed:
                raise RuntimeError(
                    'The content for this response was already consumed')

            if self.status_code == 0 or self.raw is None:
                self._content = None
            else:
                #if stream=True 
                self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()

        self._content_consumed = True

        return self._content
```
so i think the problem is `iter_content()`.And i found sometimes the length of chunk from `iter_content(chunk_size=BLOCK_SIZE)` is smaller than BLOCK_SIZE

I don't think the problem is `iter_content`, because `iter_content` is *always* used. Take a look at the definition of `session.send` [here](https://github.com/requests/requests/blob/master/requests/sessions.py#L658) to see that we always do the same thing.

So that cannot be the problem. So back to my question: do you know *for sure* that the body is corrupted? If so, how is the corruption manifesting?

> so i think the problem is iter_content().And i found sometimes the length of chunk from iter_content(chunk_size=BLOCK_SIZE) is smaller than BLOCK_SIZE

If I recall correctly, `iter_content` will return something smaller than `BLOCK_SIZE` if the content was compressed. Is that happening to you?

@Lukasa 
Sorry my English is basic,I do not know what you said the _body_ refers to what。If it means the file that I downloaded,I'm sure it is really damaged,because I can not open the downloaded .doc file.

Yeah, that's the body.

So if you have two *identical* blocks of code, one that downloads with `stream=True` and one that downloads with `stream=False`, they save two different files to disk?

@sigmavirus24 
I'm not sure if that is happening to me.If the content was compressed should I do something to ensure that the content is correct？

> So if you have two identical blocks of code, one that downloads with stream=True and one that downloads with stream=False, they save two different files to disk?

I did a small test and the result of the file stream_true.doc and stream_false.doc is the same:
```python
import requests


def stream_false():
    r = requests.get(url='http://www.uep.cl/wp-content/uploads/2016/01/TestWordDoc.doc', stream=False)
    with open('stream_false.doc', 'wb') as f: 
        for chunk in r.iter_content(chunk_size=1024*36):
            if chunk:
                f.write(chunk)
                f.flush()
    r.close()

def stream_true():
    r = requests.get(url='http://www.uep.cl/wp-content/uploads/2016/01/TestWordDoc.doc', stream=True)
    with open('stream_true.doc', 'wb') as f: 
        for chunk in r.iter_content(chunk_size=1024*36):
            if chunk:
                f.write(chunk)
                f.flush()
    r.close()


if __name__ == '__main__':
    stream_false()
    stream_true()
```

@nano3k0a that's an interesting data point but context is required. Please provide the output of `python -m requests.help` so we know the similarities and differences between your system/configuration and @MrKang 's

I found that the error was caused by single step of debugging
My development environment is:
vscode：
 1.15.0 (1.15.0)
plugins：
Python 0.7.0
Python for VSCode 0.2.3
MagicPython 1.0.12
```python
with open(tmp_full_path, 'wb') as f: 
    for chunk in r.iter_content(chunk_size=1024*36):
#set a breakpoint anywhere in this loop and then single step several times
        if len(chunk) < 1024*36:
            print len(chunk)
        if chunk:
            f.write(chunk)
            f.flush()
```

So what you're saying is that the loop above works fine without a breakpoint, and otherwise breaks?

yes,I have tested it many times.

What happens if you change the breakpoint just to be a `time.sleep`instead?

Everything is fine when using time.sleep.
```python
with open(tmp_full_path, 'wb') as f: 
    for chunk in r.iter_content(chunk_size=1024*36):
        if len(chunk) < 1024*36: 
#set a breakpoint anywhere in this loop and then single step several times,there will be a chunk that smaller than chunk_size
            print len(chunk)
        if chunk:
            f.write(chunk)
            f.flush()
```

To be clear, a chunk smaller than chunk size is not a bug. I'm worried more about *losing* data.

I just want to say that every time I get an incomplete file ,the `len(chunk) < 1024*36`will be true.
I have already said the steps to reproduce，you can set a breakpoint to test

@MrKang Sure, but that's to be expected. At the very least you will get *one* chunk smaller than that, which is the end of the file.

I've just had a similar experience -- a chunked binary read turned out different from a whole-file read.

Each chunk in the failing case was a substring of the entire file, but there were inter-chunk pieces missing.

In the process of making a demo program, I discovered that the failing case only occurs when I was running my program within PyTools  for VisualStudio, even without breakpoints in the affected code.

Weirdness.

Thanks to MrKang and Lukasa for planting a seed in my mind about breakpoints and debugging.

i wonder what if i use without `with` statement?
because i don't need to write to file, only need to iterate to read each 1024 bytes until i get what i need.
would it be ok?

```
r = request.get(url='http://down.ziyuanku.com/201708091545/b5e3765e0be509c91617da128ecf169f/Resources/ChuZhong/2017-07-12/cccee17addb349cf8966161180c3e3ea.doc', stream=True)
data=[]
for chunk in r.iter_content(chunk_size=1024*36):
    if chunk:
        data.append(chunk)
        f.flush()
r.close()
```