How to load cookies from a json input in python-requests?

Peng Yu pengyu.ut at gmail.com
Mon Aug 12 23:38:33 EDT 2019


```
import requests
s = requests.Session()
import json
s.cookies.set_cookie(requests.utils.cookiejar_from_dict(json.load(sys.stdin)))
```

I used the above command to load cookies from a json file. But I got
the following error. Does anybody know how to fix the error? Thanks.

```
Traceback (most recent call last):
  File "/xxx/xxx.py", line 15, in <module>
    s.cookies.set_cookie(requests.utils.cookiejar_from_dict(json.load(sys.stdin)))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/cookies.py",
line 345, in set_cookie
    if hasattr(cookie.value, 'startswith') and
cookie.value.startswith('"') and cookie.value.endswith('"'):
AttributeError: 'RequestsCookieJar' object has no attribute 'value'
```

-- 
Regards,
Peng



More information about the Python-list mailing list