From f6ef9b862e8b9826a834a58a286f0a99319bc00e Mon Sep 17 00:00:00 2001 From: Malfurious Date: Wed, 11 Aug 2021 00:59:58 -0400 Subject: Add notes on Python requests library Signed-off-by: Malfurious --- docs/lang/python/requests.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 docs/lang/python/requests.py diff --git a/docs/lang/python/requests.py b/docs/lang/python/requests.py new file mode 100644 index 0000000..178a1f7 --- /dev/null +++ b/docs/lang/python/requests.py @@ -0,0 +1,26 @@ +import requests +import json + +# GET +r = requests.get("https://httpbin.org/get?a=b&c=d") +print(r.headers) +print(r.text) + +# POST +r = requests.post("https://httpbin.org/post", + data={'a': 'b', 'c': 'd'}) + +# POST JSON +r = requests.post("https://httpbin.org/post", + json={'a': 'b', 'c': 'd'}) +print(r.json()) + +# Request headers +r = requests.get("https://httpbin.org/get", + headers={'DNT': '1'}) # Do not track + +# Session (any cookies obtained will be saved/sent with follow-up requests) +s = requests.Session() +r = s.post("...", + data={'username': '...', "password": '...'}) +r = s.get(".../my_user_data") -- cgit v1.2.3