如何覆盖标题Scrapy中的“连接:关闭”?

Lea*_*g C 5 python http-headers scrapy

在我的 scrapy 爬虫中,我有以下custome_settings:

 custom_settings = {
        'DEFAULT_REQUEST_HEADERS': {
            'Connection' : 'Keep-Alive'
        }
    }
Run Code Online (Sandbox Code Playgroud)

我什至尝试在 scrapy.Reqest() 中设置标题,如下所示:

 headers = {}
 headers['Connection'] : 'Keep-Alive'
 headers['User-Agent'] : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'

 for url in urls:
     yield scrapy.Request(url, headers=headers, callback = self.parse)
Run Code Online (Sandbox Code Playgroud)

但是,请求不会覆盖该值。相反,它只是将另一个“连接”附加到请求标头中。

请求数据包:

GET http://example.com HTTP/1.1
Connection: close
Connection: Keep-Alive
User-Agent: Scrapy/1.4.0 (+http://scrapy.org)
Accept-Encoding: gzip,deflate
Run Code Online (Sandbox Code Playgroud)

但是请求“连接:保持活动”被附加到请求标头而不是覆盖它。如何在 scrapy 中实际覆盖请求标头中的“连接”?