Requests currently store all headers (sent and received) as invisibly in dictionaries. Other than that, however, open the python console and write:
headers = {'X-Attribute':'A', 'X-Attribute':'B'}
What you get is undefined behavior. (This may seem reproducible, but it is completely undefined.) So you are really sending requests in this instance:
{'X-Attribute': 'A'}
What could you try (but failed):
headers = [('X-Attribute', 'A'), ('X-Attribute', 'B')]
But at least it will be a completely specific behavior (you will always send B). As @mata suggested, if your server is HTTP/1.1 compliant, then you can do this:
import collections def flatten_headers(headers): for (k, v) in list(headers.items()): if isinstance(v, collections.Iterable): headers[k] = ','.join(v) headers = {'X-Attribute': ['A', 'B', ..., 'N']} flatten_headers(headers) requests.get(url, headers=headers)
Hope this helps you.
source share