Python 3.8과 Discourse API를 사용하여 다음 코드를 통해 토픽의 태그를 가져올 수 있었습니다:
topic_url = forum_url + f'/t/{topic_id}.json'
topic_obj = requests.get(topic_url, headers=headers).json()
topic_tags = list(topic_obj.get('tags'))
제 헤더는 다음과 같습니다(API 사용자는 관리자 권한을 가짐):
headers = {
'Content-Type': 'application/json',
'Api-Key': api_key,
'Api-Username': api_username
}
하지만 동일한 헤더를 사용하여 태그를 업데이트할 수 없습니다:
update_url = forum_url + f'/t/-/{topic_id}.json'
payload = {'tags':['bmw', 'nd', 'ak', 'ca']}
r = requests.put(
update_url,
params=payload,
headers=headers
)
응답:
<Response [500]>
{'status': 500, 'error': 'Internal Server Error'}
동일한 requests 메서드, 헤더, API 자격 증명 및 URL을 사용하여 토픽 제목을 업데이트하는 데는 성공했습니다. 토픽 태그를 업데이트할 때 왜 접근이 거부되는지 고민 중입니다. 도움이 될 만한 힌트가 있다면 알려주세요. 감사합니다!