여러분, 안녕하세요. 토픽을 업데이트하는 데 문제가 있습니다. 여기에 나와 있는 것처럼 첫 번째 게시물의 id를 가져오는 것은 가능합니다. 아래 코드를 실행하면 이를 확인할 수 있습니다:
import requests
from requests.structures import CaseInsensitiveDict
url = "https://my/discourse/instance/posts/{post_id}.json"
headers = CaseInsensitiveDict()
headers["Authorization"] = "{"api-key": "{le_api_key}", "api-username": "{le_username}"}"
resp = requests.get(url, headers=headers)
print(resp.status_code)
위 코드는 200 상태 코드와 예상했던 게시물 정보를 반환합니다.
하지만 다음을 시도하면:
import requests
from requests.structures import CaseInsensitiveDict
url = "https://my/discourse/instance/posts/{post_id}.json"
headers = CaseInsensitiveDict()
headers["Authorization"] = "{"api-key": "le_api_key", "api-username": "le_username"}"
headers["Content-Type"] = "application/json"
data = """
{
"post": {
"raw": "Cool post, but here's an updated to the post's body",
"edit_reason": "I changed this because I can."
}
}
"""
resp = requests.put(url, headers=headers, data=data)
print(resp.status_code)
["BAD CSRF"] 오류가 발생합니다.
저는 관리자이며 제 키는 global입니다. 가능하면 권한이 덜 있는 키로 이 작업을 수행하고 싶습니다.
이 게시물은 API를 통해 생성한 토픽의 첫 번째이자 유일한 게시물입니다.
미리 감사드립니다 ![]()