[New-bugs-announce] [issue3924] cookielib chokes on non-integer cookie version, should ignore it instead

Denis report at bugs.python.org
Sun Sep 21 20:30:24 CEST 2008


New submission from Denis <f.pybugs at altudov.com>:

PROBLEM:

Some sites (e.g. https://itunesconnect.apple.com) sends cookies where
version is "1" instead of 1. Cookielib chokes on it so none of the
cookies work after that.

PROBLEM CODE:
    def _cookie_from_cookie_tuple(self, tup, request):
...
        name, value, standard, rest = tup
...
        version = standard.get("version", None)
        if version is not None: version = int(version) << CRASH HERE!!!



WORKAROUND:

use my own cookie jar, e.g.:

class MyCookieJar(CookieJar):
    def _cookie_from_cookie_tuple(self, tup, request):
        name, value, standard, rest = tup
        standard["version"]= None
        CookieJar._cookie_from_cookie_tuple(self, tup, request)

REAL FIX:
do not assume that version is int, keep it as string if it does not
parse as int:

CRASH STACK:

/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/cookielib.py:1577:
UserWarning: cookielib bug!
Traceback (most recent call last):
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/cookielib.py",
line 1575, in make_cookies
    parse_ns_headers(ns_hdrs), request)
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/cookielib.py",
line 1532, in _cookies_from_attrs_set
    cookie = self._cookie_from_cookie_tuple(tup, request)
  File
"/Users/denis/Documents/svn2/tson/main/sales/src/download_sales.py",
line 28, in _cookie_from_cookie_tuple
    CookieJar._cookie_from_cookie_tuple(self, tup, request)
  File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/cookielib.py",
line 1451, in _cookie_from_cookie_tuple
    if version is not None: version = int(version)
ValueError: invalid literal for int() with base 10: '"1"'

  _warn_unhandled_exception()

----------
components: None
messages: 73518
nosy: DenNukem
severity: normal
status: open
title: cookielib chokes on non-integer cookie version, should ignore it instead
type: crash
versions: Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3924>
_______________________________________


More information about the New-bugs-announce mailing list