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

后端 未结 2 1953

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.
    
    0 讨论(0)
  • 2021-01-07 00:04

    I had the same problem but without stream, and as stone mini said, just apply "with" clause before to make sure your request is closed before a new request.

        with requests.request("POST", url_base, json=task, headers=headers) as report:
            print('report: ', report)
    
    0 讨论(0)
提交回复
热议问题