GET 요청에는 항상 쿼리 문자열이 포함되어 있으며, POST 데이터는 절대 포함되지 않습니다(이것이 413 payload too large 오류가 발생하는 이유이며, 서버는 POST 데이터를 기대하지 않습니다). 서버에서 데이터를 변경하지 않고 조회할 때는 거의 항상 POST가 아닌 GET을 사용합니다. 따라서 data= 대신 params=를 사용해야 합니다.
해당 API 호출에 대한 문서가 다소 불명확하게 작성되어 있다고 생각합니다("Request Body schema"는 실제로 POST data를 암시합니다) 그래서 이 이슈를 #contribute:bug로 옮기겠습니다. 그리고 아무것도 지불하실 필요가 없습니다.
import requests
import json
def get_post_from_topic(topic_id, post_id):
endpoint = f"https://forum.example.com/t/{topic_id}/posts.json"
api_username = 'system'
api_key = 'REDACTED'
headers = {
"Content-Type": "application/json",
"Api-Key": api_key,
"Api-Username": api_username,
}
params = {
"post_ids[]": post_id
}
response = requests.get(endpoint, headers=headers, params = params)
if response.status_code == 200:
return response
response = get_post_from_topic(6,8)
print(response.json())
{"post_stream": {"posts": [{"id": 8, "name": "system", "username": "system", "avatar_template": "/images/discourse-logo-sketch-small.png", "created_at": "2022-06-26T04:44:23.637Z", "cooked": "<p><a name=\"collect\"></a></p>\n<h2>\n<a name=\"what-information-do-we-collectcollect-1\" class=\"anchor\" href=\"#what-information-do-we-collectcollect-1\"></a><a href=\"#collect\">What information do we collect...