votes up 1

max-age: %s must be integer

Package:
Exception Class:
TypeError

Raise code

    """Convert a Morsel object into a Cookie containing the one k/v pair."""

    expires = None
    if morsel['max-age']:
        try:
            expires = int(time.time() + int(morsel['max-age']))
        except ValueError:
            raise TypeError('max-age: %s must be integer' % morsel['max-age'])
    elif morsel['expires']:
        time_template = '%a, %d-%b-%Y %H:%M:%S GMT'
        expires = calendar.timegm(
            time.strptime(morsel['expires'], time_template)
        )
    return create_cookie(
        comment=morsel['comment'],

Ways to fix

votes up 0 votes down

Summary:

When using requests.cookies.morsel_to_cookie functiin, the morsel objects max-age key must have an integer value:

Reproduce:

from requests.cookies import morsel_to_cookie
from  http.cookies import Morsel

newcookie = Morsel()
newcookie.key = 'examplecookie'
newcookie.value = 'val'
newcookie.coded_value = 'val'
newcookie['max-age'] = "3600" # max-age not integer

cookie = morsel_to_cookie(newcookie) 

FIX:

from requests.cookies import morsel_to_cookie
from  http.cookies import Morsel

newcookie = Morsel()
newcookie.key = 'examplecookie'
newcookie.value = 'val'
newcookie.coded_value = 'val'
newcookie['max-age'] = 3600 # max-age must be integer

cookie = morsel_to_cookie(newcookie) 

Jun 01, 2021 cRyp70s answer
cRyp70s 113

Add a possible fix

Please authorize to post fix