Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between requests.request('POST' and request.post

Tags:

python

what would it be the difference between these two sentences:

res = requests.request('POST', url)

and

res = requests.request.post(url)
like image 888
NeDiaz Avatar asked Jun 16 '26 06:06

NeDiaz


1 Answers

They are pretty much the same thing: https://github.com/psf/requests/blob/177dd90f18a8f4dc79a7d2049f0a3f4fcc5932a0/requests/api.py#L103-L115

requests.post(…) is just a wrapper around requests.request('POST', …). As long as you're using standards methods, the former helps readability and reduces the risk of easily avoidable mistakes, while writing the verb.

Edit: updated the source reference, since the domain docs.python-requests.org has expired, and the previous link (http://docs.python-requests.org/en/master/_modules/requests/api/#post) is now invalid.

like image 167
Varstahl Avatar answered Jun 18 '26 20:06

Varstahl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!