jjlee/mechanize — Issue #55: Cookie with the name expires isn't parsed correctly
Author: chirayu
Created: 2012-01-19 08:53:05+00:00
State: open

The request/response header log below shows a cookie named expires being set by the server. parse_ns_headers (in _headersutil.py) treats the cookie name as a header attribute and transforms the value to an integer. In subsequent requests to the same domain, mechanize fails as the cookie value is an integer. Traceback below.

```
$ curl --verbose "http://www.amsterdamprinting.com/Article/Study+Entrepreneurs+struggle+with+financial+literacy+/800622390/Default.aspx" > /dev/null
* About to connect() to www.amsterdamprinting.com port 80 (#0)
* Trying 184.169.77.22... connected
* Connected to www.amsterdamprinting.com (184.169.77.22) port 80 (#0)
> GET /Article/Study+Entrepreneurs+struggle+with+financial+literacy+/800622390/Default.aspx HTTP/1.1
> User-Agent: curl/7.19.4 (i686-pc-linux-gnu) libcurl/7.19.4 zlib/1.2.3.3 c-ares/1.6.0
> Host: www.amsterdamprinting.com
> Accept: */*
>
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0< HTTP/1.1 200 OK
< Date: Thu, 19 Jan 2012 08:24:40 GMT
< Content-Type: text/html; charset=utf-8
< Server: Microsoft-IIS/6.0
< X-Powered-By: ASP.NET
< X-AspNet-Version: 2.0.50727
< Set-Cookie: ASP.NET_SessionId=n3gafu550m4ykq45tgrabkvr; path=/; HttpOnly
< Set-Cookie: ; expires=Fri, 18-Jan-2013 08:24:40 GMT; path=/
< Accept-Ranges: bytes
< Cache-Control: no-store
< Pragma: no-cache
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< x-cdn: Served by WebAcceleration
< Transfer-Encoding: chunked
< Connection: Keep-Alive
<
```

```
f = mechanize.urlopen(url)
File "build/bdist.linux-x86_64/egg/mechanize/_opener.py", line 420, in urlopen
File "build/bdist.linux-x86_64/egg/mechanize/_opener.py", line 185, in open
File "build/bdist.linux-x86_64/egg/mechanize/_http.py", line 346, in http_request
File "build/bdist.linux-x86_64/egg/mechanize/_clientcookie.py", line 1178, in add_cookie_header
File "build/bdist.linux-x86_64/egg/mechanize/_clientcookie.py", line 1133, in _cookie_attrs
TypeError: expected string or buffer
```