requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read, 512 more expected)', IncompleteRead

后端 未结 2 1961

I wanted to write a program to fetch tweets from Twitter and then do sentiment analysis. I wrote the following code and got the error even after importing all the necessary

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 00:00

    If you set stream to True when making a request, Requests cannot release the connection back to the pool unless you consume all the data or call Response.close. This can lead to inefficiency with connections. If you find yourself partially reading request bodies (or not reading them at all) while using stream=True, you should make the request within a with statement to ensure it’s always closed:

    with requests.get('http://httpbin.org/get', stream=True) as r:
        # Do things with the response here.
    

提交回复
热议问题