Skip to content

Nicer repr for httpx.Cookie, displaying stored cookies. #1377

Closed

Description

@schrodienieur

When i'm trying to save cookies with these code:
with open('Cookies/cookies.txt', 'w') as f:
json.dump(dict(client.cookies), f)

i got error:
raise CookieConflict(message)
httpx.CookieConflict: Multiple cookies exist with name=client_type

i'm also curios, how to print all session cookies like in requests module (using print(session.cookies)
when im using print(client.cookies) with httpx module, the result was <httpx.Cookies object at 0x03B50E20>

can you help me?

Activity

  1. VeNoMouS commented on Nov 5, 2020

    @VeNoMouS

    @Mavic111 use client.cookies.jar to print, there will be more than 1 cookie with the same key name in there, so when your converting to a dict, that is your issue.

  2. lovelydinosaur commented on Nov 13, 2020

    @lovelydinosaur
    Member

    Requests will give you the same behaviour wrt. multiple cookies with the same name...

    >>> dict(s.cookies)
    ...
    requests.cookies.CookieConflictError: There are multiple cookies with name, 'name'

    Tho I. would agree that our Cookies repr would be nicer if it displayed the stored cookies. In the same way that RequestsCookieJar does...

    >>> print(s.cookies)
    <RequestsCookieJar[<Cookie name=value for httpbin.org/>, <Cookie name=value2 for www.httpbin.org/>]>
  3. changed the title [-]Can't print session cookies and get CookieConflict when saving cookies[/-] [+]Nicer repr for `httpx.Cookie`, displaying stored cookies.[/+] on Nov 13, 2020
  4. lovelydinosaur commented on Nov 13, 2020

    @lovelydinosaur
    Member

    I've retitled the issue to reflect the one aspect of this that I think we could improve on.

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

    enhancementNew feature or requestrequests-compatIssues related to Requests backwards compatibilityuser-experienceEnsuring that users have a good experience using the library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions