I am using urllib2 to interact with a website that sends back multiple Set-Cookie headers. However the response header dictionary only contains one – seems the duplicate keys are overriding each other.
Is there a way to access duplicate headers with urllib2?
According to urllib2 docs, the
.headersattribute of the result URL object is anhttplib.HTTPMessage(which appears to be undocumented, at least in the Python docs).However,
So, if you access u.headers[‘Set-Cookie’], you should get one Set-Cookie header with the values separated by commas.
Indeed, this appears to be the case.