0

I have some cookies in python stored like this:

    cookie = [
{"""
    "domain": ".justdial.com",
    "expirationDate": 1577653041.993055,
    "hostOnly": false,
    "httpOnly": true,
    "name": "_ctk",
    "path": "/",
    "sameSite": "no_restriction",
    "secure": false,
    "session": false,
    "storeId": "0",
    "value": "893b0b69e25c0359d6e1fd88f16fea90a4bd2e0e8f8356e80bfc572e7f7e1343",
    "id": 1"""
},
{"""
    "domain": ".justdial.com",
    "expirationDate": 1546136368,
    "hostOnly": false,
    "httpOnly": false,
    "name": "_fbp",
    "path": "/",
    "sameSite": "no_restriction",
    "secure": false,
    "session": false,
    "storeId": "0",
    "value": "fb.1.1546114608524.1389346931",
    "id": 2"""
}
]

requests.post(URL, cookies=cookie)

I am trying to send these cookies using Requests, but that does not work. Is the format wrong, or the way that I am sending it?

Thanks for the help! Using RequestsCookieJar worked, but I found another way: I saved it to a separate file, then, using the json library I got it in the right format and was able to send the cookies.

1
  • "Does not work" is a much too imprecise error description. What is the error or output, what actually happens (edit the question to show it as properly formatted text)? Commented Dec 30, 2018 at 4:45

1 Answer 1

1

In your code, cookie is a list. You need to send a dict, or you can use the requests.cookies.RequestsCookieJar() object:

From the docs:

>>> jar = requests.cookies.RequestsCookieJar()
>>> jar.set('tasty_cookie', 'yum', domain='httpbin.org', path='/cookies')
>>> jar.set('gross_cookie', 'blech', domain='httpbin.org', path='/elsewhere')
>>> url = 'https://httpbin.org/cookies'
>>> r = requests.get(url, cookies=jar)
>>> r.text
'{"cookies": {"tasty_cookie": "yum"}}'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.