Skip to content

http.cookies.BaseCookie (and SimpleCookie) can't be load from dict #51695

Closed

Description

@tcourbon
mannequin
BPO 7446
Nosy @amauryfa
Superseder
  • bpo-5275: BaseCookie.load doesn't create Morsel objects for mappings
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-12-05.21:12:51.828>
    created_at = <Date 2009-12-05.20:36:52.586>
    labels = ['library']
    title = "http.cookies.BaseCookie (and SimpleCookie) can't be load from dict"
    updated_at = <Date 2009-12-05.21:12:51.805>
    user = 'https://bugs.python.org/tcourbon'

    bugs.python.org fields:

    activity = <Date 2009-12-05.21:12:51.805>
    actor = 'amaury.forgeotdarc'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-12-05.21:12:51.828>
    closer = 'amaury.forgeotdarc'
    components = ['Library (Lib)']
    creation = <Date 2009-12-05.20:36:52.586>
    creator = 'tcourbon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 7446
    keywords = []
    message_count = 2.0
    messages = ['96007', '96009']
    nosy_count = 2.0
    nosy_names = ['amaury.forgeotdarc', 'tcourbon']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = None
    status = 'closed'
    superseder = '5275'
    type = None
    url = 'https://bugs.python.org/issue7446'
    versions = ['Python 3.1']

    Activity

    1. tcourbon commented on Dec 5, 2009

      tcourbonmannequin
      MannequinAuthor

      Hi there !

      According the documentation [1], the following code should work :
      >>> from http.cookies import SimpleCookie
      >>> c = SimpleCookie({'field1': 'value1', 'field2': 'value2'})
      >>> print(c)
      'Set-Cookie: field1=value1\r\nSet-Cookie: field2=value2'
      
      But an exception is raised : 
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "c:\python31\lib\http\cookies.py", line 507, in output
          result.append( V.output(attrs, header) )
      AttributeError: 'str' object has no attribute 'output'

      in BaseCookie.load(...) the call to BaseCookie.update(rawdata) seem to
      use dict.__setitem__ instead of BaseCookie.__setitem__.

      Despite it's weird (I believe that the __setitem__ of the child class
      should be used) I don't know why.

      I don't have a solution to this underlying issue so I propose to define
      an update method for BaseCookie:
      def update(self, other=None, **kwargs):
      if other is None:
      other = kwargs
      elif not hasattr(other, 'items'):
      other = dict(other)
      for k, v in other.items():
      self[k] = v

      This method behave like the dict one.

      Hope it help and it's not a duplicate.

      Regards,
      Thomas

      [1] :
      http://docs.python.org/3.1/library/http.cookies.html#http.cookies.BaseCookie.load

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Dec 5, 2009
    3. amauryfa commented on Dec 5, 2009

      @amauryfa
      Contributor

      This was already corrected with bpo-5275. Thanks however for the report.

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions