From 961790f95c7c06dc073d882acb28810a22d27b77 Mon Sep 17 00:00:00 2001 From: wasw100 Date: Thu, 6 Jun 2013 19:15:09 +0800 Subject: [PATCH 1/2] cookies.morsel_to_cookie(morsel) raise TypeError repaired. morsel_to_cookie(mosel) method raise TypeError: create_cookie() got unexpected keyword arguments: ['path_specified', 'domain_specified', 'port_specified', 'domain_initial_dot']. so we should remove these param from create_cookie(...) --- requests/cookies.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/requests/cookies.py b/requests/cookies.py index d759d0a9..6b2d4cd5 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -359,12 +359,8 @@ def morsel_to_cookie(morsel): value=morsel.value, version=morsel['version'] or 0, port=None, - port_specified=False, domain=morsel['domain'], - domain_specified=bool(morsel['domain']), - domain_initial_dot=morsel['domain'].startswith('.'), path=morsel['path'], - path_specified=bool(morsel['path']), secure=bool(morsel['secure']), expires=morsel['max-age'] or morsel['expires'], discard=False, From 767f758aacba8f70721fc1abbeb1d8ad929a084c Mon Sep 17 00:00:00 2001 From: wasw100 Date: Fri, 7 Jun 2013 00:02:45 +0800 Subject: [PATCH 2/2] cookies.morsel_to_cookie morsel['expires'] can't be strtime, and max-age convert to expires problem repair --- requests/cookies.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/requests/cookies.py b/requests/cookies.py index 6b2d4cd5..d62f0cd1 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -6,6 +6,7 @@ Compatibility code to be able to use `cookielib.CookieJar` with requests. requests.utils imports from here, so be careful with imports. """ +import time import collections from .compat import cookielib, urlparse, Morsel @@ -354,6 +355,14 @@ def create_cookie(name, value, **kwargs): def morsel_to_cookie(morsel): """Convert a Morsel object into a Cookie containing the one k/v pair.""" + expires = None + if morsel["max-age"]: + expires = time.time() + morsel["max-age"] + elif morsel['expires']: + expires = morsel['expires'] + if type(expires) == type(""): + time_template = "%a, %d-%b-%Y %H:%M:%S GMT" + expires = time.mktime(time.strptime(expires, time_template)) c = create_cookie( name=morsel.key, value=morsel.value, @@ -362,7 +371,7 @@ def morsel_to_cookie(morsel): domain=morsel['domain'], path=morsel['path'], secure=bool(morsel['secure']), - expires=morsel['max-age'] or morsel['expires'], + expires=expires, discard=False, comment=morsel['comment'], comment_url=bool(morsel['comment']),