Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python requests package 1.2.3 on Python 3.x has an issue when used with custom headers, and possibly only when sending binary data (data=b'bytes'). This hotpatches it, and works here in testing when I'm trying to set headers={'Content-Type': 'my-custom-content-type'} in the .post() call.
- from requests.models import PreparedRequest
- from requests.structures import CaseInsensitiveDict
- # hot-patch requests to avoid problem with
- def prepare_headers(self, headers):
- if headers:
- headers = dict((name, value) for name, value in headers.items())
- self.headers = CaseInsensitiveDict(headers)
- else:
- self.headers = CaseInsensitiveDict()
- PreparedRequest.prepare_headers = prepare_headers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement