Python-Requests close http connection

前端 未结 7 1360
既然无缘
既然无缘 2020-11-27 03:14

I was wondering, how do you close a connection with Requests (python-requests.org)?

With httplib it\'s HTTPConnection.close(), but how do I

相关标签:
7条回答
  • 2020-11-27 04:08

    To remove the "keep-alive" header in requests, I just created it from the Request object and then send it with Session

    headers = {
    'Host' : '1.2.3.4',
    'User-Agent' : 'Test client (x86_64-pc-linux-gnu 7.16.3)',
    'Accept' : '*/*',
    'Accept-Encoding' : 'deflate, gzip',
    'Accept-Language' : 'it_IT'
    }
    
    url = "https://stream.twitter.com/1/statuses/filter.json"
    #r = requests.get(url, headers = headers) #this triggers keep-alive: True
    s = requests.Session()
    r = requests.Request('GET', url, headers)
    
    0 讨论(0)
提交回复
热议问题