How to prevent Scrapy from automatically capitalizing the key of header

question

when developing a crawler with scrapy, grab the package with fiddler and find that scrapy will automatically capitalize the key of the requested header, such as accept-encoding into Accept-Encoding , and accept into Accept . The problem is that I don"t want to convert uppercase for some header due to validation problems.

methods that have been tried

I tried to change key.title () in the normkey method in scrapy/http/headers.py to key.lower ()

.
class Headers(CaselessDict):
    ...
    def normkey(self, key):
        """Normalize key to bytes"""
        return self._tobytes(key.title())  -sharp  key.lower()

seems to work, but in the end, what you see in fiddler is capitalized and verification fails

in addition, if you use requests to send requests, this will not happen. Packet grabbing is normal
, so you can basically rule out software and other environmental problems

.

I would like to ask you, in which step does scrapy convert the key of header into the capitalized

of the word?
Mar.09,2022

write header with no uppercase initials on top of the spider class in the spider file

from twisted.web.http_headers import Headers as TwistedHeaders

TwistedHeaders._caseMappings.update({
    b'uuid': b'uuid',
    b'content-type': b'content-type',
})

has the problem been solved? It still doesn't work when I set it up through TwistedHeaders._caseMappings.update. This code is run in the start_request () method, and the first letter of key in headers is still capitalized.

Menu