Set Cookie does not work properly with HTTP 302

Python Requests 2.4.3
Python 3.4 - windows 7 (64 bit)

Scenario:
Performing this request:

GET on URL: http://fantacalcio.repubblica.it/login.phpSSID=exjlkfpnaqaqpzqrrrzxjehfxpravrhdvjzjrkqpkraqdpee

I send this Header:
{'Pragma': 'max-age=0', 'Origin': 'https://login.kataweb.it', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36', 'Accept-Language': 'it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2', 'Host': 'login.kataweb.it', 'Cache-Control': 'no-cache', 'Referer': 'https://login.kataweb.it/registrazione/repubblicafantacalcio/login.jsp?ssoOnly=false&backurl=http%3A%2F%2Fwww.fantacalcio.kataweb.it%2Fsocial%2Fsites%2Ffantacalcio%2Ffantacalciosocial%2Fcampionato%2Floader.php%3FmClose%3D2%26backUrl%3Dhttp%253A%2F%2Ffantacalcio.repubblica.it%2Flogin.php&optbackurl=http%3A%2F%2Fwww.fantacalcio.kataweb.it%2Fsocial%2Fsites%2Ffantacalcio%2Ffantacalciosocial%2Fcampionato%2Floader.php%3FmClose%3D2%26backUrl%3Dhttp%253A%2F%2Ffantacalcio.repubblica.it%2Flogin.php', 'Accept-Encoding': 'gzip,deflate,sdch', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,_/_;q=0.8', 'Proxy-Connection': 'keep-alive', 'Connection': 'keep-alive'}

and I receive this answer: (a HTTP  302) with header:

{'Expires': 'Thu, 11 Dec 2014 10:22:37 GMT', 'Set-Cookie': 'fantarep_new=0298b7c7bdd9d45ecf5749e8c1fdd5_383207; expires=Fri, 12-Dec-2014 10:22:38 GMT; path=/; domain=.fantacalcio.repubblica.it', 'Age': '0', 'X-Cacheable': 'NO:Not Cacheable', 'Accept-Ranges': 'bytes', 'Content-Length': '20', 'Content-Type': 'text/html', 'Proxy-Connection': 'keep-alive', 'X-Cache-Lookup': 'MISS from proxy1.altranit.corp.altran.com:8080', 'X-Cache': 'MISS from proxy1.altranit.corp.altran.com', 'Via': '1.0 proxy1.altranit.corp.altran.com:8080 (squid/2.6.STABLE21)', 'Vary': 'Accept-Encoding', 'Content-Encoding': 'gzip', 'Server': 'Apache', 'Date': 'Thu, 11 Dec 2014 10:22:38 GMT', 'Cache-Control': 'max-age=0', 'Location': 'index.php?page=sqdlist&ck_fantacalcio=0298b7c7bdd9d45ecf5749e8c1fdd5&global=0&first=1'}

I've this Cookies (BEFORE THE REQUEST IS PERFORMED)
{'FCSOCIAL': 'FCSOCIAL_bb828ef8c292284073012f2931d739', 'gac_3_8ODxzU7xh4eFL2a_mtwjaR5JKoyX0az0MLmAfUYg8kCc2Eo63vmDP9Z3tSI7lS0h': 'VC1_E4E1B47C0B7B0D2C71751CA6855405AF_c718efX2eyW82F0KfQyyZN6hRDxp-4Gn7zYqHu-PRsb2SxHyopuk99ljuVBhks6c8E5PtMxYZEUy0IATFSkvHUPiuc4eqRyUMAYrmQLwDOy_72I4tzk6xOpSJf3s1pLTekn-zZ-TYnkIsk0vsWeHWQ%3D%3D', 'KWSSO': '"{hashId:4648b93f7efac4f16581aab27b7396e4,sessionId:1418293351099,criptKey:1ADBC72C64E0735AA89F96D77294AC827267F01B8FF4397D8D7095B4FD591E59E7033A46928DC087726DB1602EFCFCC5C1FE4A5C0E378C7C}"', 'JSESSIONID': 'F1124C14EE69AF8794998C5BF4BF65D6'}

BUT the SET COOKIE --> 'fantarep_new=0298b7c7bdd9d45ecf5749e8c1fdd5_383207; is ignored.

The http_session.cookies.get_dict()) after the 302 does not return the list updated.

Hoping can help


Can you run your code and then do this please?

``` python
for h in r.history:
    print h.status_code
    print h.headers
    print h.request.headers
```


## Your problem is that you're specifying the Host header. We special case cookie parsing when you do that.

Sent from my Android device with K-9 Mail. Please excuse my brevity.


Lukasa, your code does not produce anything... I'm sure that it's my fault.

I have:

mysession=Session()
......[SOME CODE]
myget=mysession.get(nexturl, proxies=myproxy,allow_redirects=False)
print_details(mysession,"GET",myget)

where with print_details I have a function designed just to debug:

def print_details(http_session,metodo,http_request):
    print("\n METODO:",metodo)
    print("URL:",http_request.url)
    print("HEADER RICHIESTA:",http_session.headers)
    print("CODICE RISPOSTA:",http_request.status_code)
    print("COOKIES SESSIONE:",http_session.cookies.get_dict())
    print("HEADER RISPOSTA:",http_request.headers)

I'm less than newbie in Python, but I've noted that if a HTTP response have more than one SET_COOKIE the second one is not considered. (this is an additional problem...that I'd like to investigate more before open a bug)

Thank you for your patience


This is a direct consequence of supportiing https://github.com/kennethreitz/requests/issues/1638. You should remove your `Host` header that you specify and _then_ this should just work @antoniofelleca 


Ok, I'll try. 

But the result is that is not possible to specify a header?

Is it correct?

Thanks


You should almost never specify the `Host` header. You _can_ specify other headers. You _can_ specify the `Host` header, but you _should not_ specify it, especially if you want requests to handle these cookies for you


@antoniofelleca any updates?


Hi,

I've run some tests: sigmavirus24 was right! Without specifying HOST header both issues disappear.

Any server header with a double SET COOKIE was correctly handled, and the set cookie in 302 work fine.

Let me thank you for your support and patience. Probably this [correct] behaviour should be descripted: I've met some discussions on Stackoverflow reporting this (false)issue.