How to send cookies in a post request with the Python Requests library?

Ricardo Altamirano :

I'm trying to use the Requests library to send cookies with a post request, but I'm not sure how to actually set up the cookies based on its documentation. The script is for use on Wikipedia, and the cookie(s) that need to be sent are of this form:

enwiki_session=17ab96bd8ffbe8ca58a78657a918558e; path=/; domain=.wikipedia.com; HttpOnly

However, the requests documentation quickstart gives this as the only example:

cookies = dict(cookies_are='working')

How can I encode a cookie like the above using this library? Do I need to make it with python's standard cookie library, then send it along with the POST request?

Kenneth Reitz :

The latest release of Requests will build CookieJars for you from simple dictionaries.

import requests

cookies = {'enwiki_session': '17ab96bd8ffbe8ca58a78657a918558'}

r = requests.post('http://wikipedia.org', cookies=cookies)

Enjoy :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to send cookies in a post request with the Python Requests library?

How to make a post request with the Python requests library?

How to have Python3 requests library send actual Content-Length with post request instead of 0?

How to send '-X POST' using 'requests' library in Python?

How to send a post request with data using python requests module?

Making a post request with requests library python

Why can't I send `None` as data in a POST request using Python's `requests` library?

How to send requests using custom cookies with Request-promise

What is the correct format for sending cookies in a post request with Python Requests?

Python requests, how to send json request without " "

PYTHON: requests.post() how to send request_body encoded as application/x-www-form-urlencoded

How to send POST request using Python-Requests to a Java Serverlet Endpoint

How do I sign a POST request using HMAC-SHA512 and the Python requests library?

How to store XML received from POST XML request in its correct format? Python requests library

How do I send a post request using the Request library and Bluebird?

Send http post request with unicoded data using python requests

Python3: JSON POST Request WITHOUT requests library

How to send raw data in a POST request Python

How to send urlencoded parameters in POST request in python

Requests library to send json for API Post

How do HTTP redirect requests send cookies?

python requests post query fails:cookies?

Python requests http post data with cookies

Python Requests: Logging into website using POST and Cookies

Python post requests and read cookies in the response

How to send POST request?

using requests.post to send a request with a certificate

Python + requests, How I send username & password in POST?

Python How to GET Image and then POST (via requests library)