I want to turn incoming HTTP requests' headers into dictionaries and clone then via the "JSON trick." request.headers
is an object that acts like a dictionary, but actually isn't a dictionary.
json.loads(json.dumps(request.headers))
The above-mentioned line of code results in this error:
TypeError: EnvironHeaders([•••]) is not JSON serializable
How do I convert a werkzeug.datastructures.EnvironHeaders
object to a dictionary?
Attempt #1:
json.loads(json.dumps({k: v for k, v in request.headers.iteritems()}))
Attempt #2:
json.loads(json.dumps({k: request.headers[k] for k in request.headers.keys()}))
Both of them throw this exception:
ValueError: too many values to unpack