简体   繁体   中英

Python: requests.get ignores the last record

This is my code:

response = requests.get(apiurl+'api/v1/watch/services',
                         auth=(apiuser,apipass), verify=False, stream=True)
for line in response.iter_lines():
    try:
        data = json.loads(line.decode('utf-8'))
        pprint.pprint(data)
    except Exception as e:
        pprint.pprint(e)
        pass

Please note the stream=True .

The problem is, when I have a b c d on the input, the script just outputs a b and c . Then, when e comes on input, the script outputs d .

What am I doing wrong?

OK so the answer is a bit unexpected for me.

Updating python from 3.4 to 3.5 helped, nothing else changed.

Hope this answer helps someone else fighting this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM