Różnice
Różnice między wybraną wersją a wersją aktualną.
| Poprzednia rewizja po obu stronach Poprzednia wersja Nowa wersja | Poprzednia wersja | ||
| programowanie:python:http [2024/09/09 14:52] – usunięto sases | programowanie:python:http [2024/10/09 19:18] (aktualna) – sases | ||
|---|---|---|---|
| Linia 1: | Linia 1: | ||
| + | ====== Python HTTP ====== | ||
| + | |||
| + | ===== request ===== | ||
| + | <code python> | ||
| + | import requests | ||
| + | |||
| + | html = requests.get(" | ||
| + | print(html.text) | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | |||
| + | ==== get ==== | ||
| + | <code python> | ||
| + | import requests | ||
| + | |||
| + | url = ' | ||
| + | |||
| + | response = requests.get(url) | ||
| + | |||
| + | if response.status_code == 200: | ||
| + | data = response.json() | ||
| + | print(data) | ||
| + | |||
| + | key_value = data[" | ||
| + | |||
| + | if key_value is not None: | ||
| + | print(key_value) | ||
| + | else: | ||
| + | print(" | ||
| + | else: | ||
| + | print(f' | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | |||
| + | ==== post ==== | ||
| + | <code python> | ||
| + | import requests | ||
| + | |||
| + | url = ' | ||
| + | data = { | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | |||
| + | response = requests.post(url, | ||
| + | |||
| + | if response.status_code == 201: | ||
| + | print(" | ||
| + | print(response.json()) | ||
| + | else: | ||
| + | print(f' | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | |||
| + | ==== patch ==== | ||
| + | <code python> | ||
| + | import requests | ||
| + | |||
| + | url = ' | ||
| + | data = { | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | |||
| + | response = requests.patch(url, | ||
| + | |||
| + | if response.status_code == 200: | ||
| + | print(" | ||
| + | print(response.json()) | ||
| + | else: | ||
| + | print(f' | ||
| + | </ | ||