psf / psf/requests

requests.cookies.RequestsCookieJar: popitem() does not work

Open
#6,190 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
54.3k
Forks
10.4k
Avg merge
16h 43m
Merged PRs (30d)
3

Description

requests.cookies.RequestsCookieJar's popitem() method doesn't seem to work even if cookies is not empty.

Expected Result

From the doc:

remove and return some (key, value) pair as a 2-tuple; but raise KeyError if D is empty.

(Also, I'm not sure what exactly is "D" here. I assume it means the cookies obj itself.)

Actual Result

It always raises KeyError even when it's not empty.

Reproduction Steps

import requests

r = requests.get('https://google.com')
print(len(r.cookies)) # = 3

r.cookies.popitem()

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "4.0.0"
  },
  "charset_normalizer": {
    "version": "2.0.10"
  },
  "cryptography": {
    "version": "3.4.8"
  },
  "idna": {
    "version": "2.10"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.9.1"
  },
  "platform": {
    "release": "10",
    "system": "Windows"
  },
  "pyOpenSSL": {
    "openssl_version": "101010cf",
    "version": "20.0.1"
  },
  "requests": {
    "version": "2.28.1"
  },
  "system_ssl": {
    "version": "1010107f"
  },
  "urllib3": {
    "version": "1.26.3"
  },
  "using_charset_normalizer": false,
  "using_pyopenssl": true
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided requests.get and r.cookies.popitem() snippet, then inspect RequestsCookieJar.popitem and its surrounding cookie-container behavior. Done means popitem() removes and returns a (key, value) pair from a non-empty jar while still raising KeyError for an empty jar.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.