Pokaż stronęPoprzednie wersjeOdnośnikiDo góry Ta strona jest tylko do odczytu. Możesz wyświetlić źródła tej strony ale nie możesz ich zmienić. ====== Python HTTP ====== ===== request ===== <code python> import requests html = requests.get("https://sases.pl") print(html.text) </code> \\ \\ ==== get ==== <code python> import requests url = 'http://example.com/api/resource/' response = requests.get(url) if response.status_code == 200: data = response.json() print(data) key_value = data["key"] if key_value is not None: print(key_value) else: print("Key not found") else: print(f'Błąd: {response.status_code}') </code> \\ \\ ==== post ==== <code python> import requests url = 'http://example.com/api/resource/' data = { "key1": "value", "key2": "value" } response = requests.post(url, json=data) if response.status_code == 201: print("Utworzono nowy zasób.") print(response.json()) else: print(f'Błąd: {response.status_code}') </code> \\ \\ ==== patch ==== <code python> import requests url = 'http://example.com/api/resource/{id}/' data = { "key1": "new_value", "key2": "new_value" } response = requests.patch(url, json=data) if response.status_code == 200: print("Zasób został zaktualizowany.") print(response.json()) else: print(f'Błąd: {response.status_code}') </code> programowanie/python/http.txt ostatnio zmienione: 2024/10/09 19:18przez sases