diff options
author | Malfurious <m@lfurio.us> | 2021-08-11 00:59:58 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2021-08-11 00:59:58 -0400 |
commit | f6ef9b862e8b9826a834a58a286f0a99319bc00e (patch) | |
tree | 3ac68d602591a66b0e3b3e9736eafe17d17bcb52 /docs/lang | |
parent | 35eb45c4b6eebdf7ba907f412f55a3dff4c0d68d (diff) | |
download | lib-des-gnux-f6ef9b862e8b9826a834a58a286f0a99319bc00e.tar.gz lib-des-gnux-f6ef9b862e8b9826a834a58a286f0a99319bc00e.zip |
Add notes on Python requests library
Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'docs/lang')
-rw-r--r-- | docs/lang/python/requests.py | 26 |
1 files changed, 26 insertions, 0 deletions
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") |