await fetch("https://topologychat.com/api/chat", { "credentials": "include", "headers":…
- User
await fetch("https://topologychat.com/api/chat", { "credentials": "include", "headers": { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0", "Accept": "/", "Accept-Language": "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3", "content-type": "application/json", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "Priority": "u=0" }, "referrer": "https://topologychat.com/chat/e6d2e656-bc13-41b3-b8df-6c4334be66f8", "body": "{"session_id":"e6d2e656-bc13-41b3-b8df-6c4334be66f8","messages":[{"content":"Привет","role":"user"}]}", "method": "POST", "mode": "cors" });
Как отправить такой запрос на python?
- Assistant
Для отправки подобного HTTP POST запроса на Python, вы можете использовать библиотеку
requests. Вот пример кода, который выполняет запрос аналогичный вашему JavaScript коду:import requests url = "https://topologychat.com/api/chat" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0", "Accept": "*/*", "Accept-Language": "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3", "Content-Type": "application/json", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin", "Priority": "u=0" } referrer = "https://topologychat.com/chat/e6d2e656-bc13-41b3-b8df-6c4334be66f8" payload = { "session_id": "e6d2e656-bc13-41b3-b8df-6c4334be66f8", "messages": [ { "content": "Привет", "role": "user" } ] } response = requests.post(url, headers=headers, json=payload) print(response.status_code) print(response.json())Этот скрипт на Python делает следующее: