Discourse Data Explorer SQL 쿼리

여기에 게시된 질문(`DataExplorer::ValidationError: Missing parameter` when running Data Explorer queries with [params] via API)과 매우 유사하지만 다른 질문이 있습니다.

Data Explorer의 내 쿼리는 다음과 같습니다:

-- [params]
-- topic_id :topic_id

SELECT * FROM posts WHERE topic_id = :topic_id

Data Explorer에서는 잘 작동합니다. 하지만 API를 통해 실행하려고 하면 다음 오류가 발생합니다:

{"success":false,"errors":["DiscourseDataExplorer::ValidationError: Missing parameter topic_id of type topic_id"]}'

제 Python 요청 코드는 다음과 같습니다:


headers = {
    'Content-Type': 'multipart/form-data;',
    'Api-Key': API_KEY,
    'Api-Username': USERNAME_SYSTEM
}

params = {"topic_id": 398}

response = requests.post(url="[REDACTED]/admin/plugins/explorer/queries/10/run", headers=headers, params=params)

오류 메시지를 통해 "topic_id"를 문자열로 전달할 수 없다는 것을 알 수 있지만, 이를 키로 전달하는 다른 방법을 찾지 못하고 있습니다. 어떤 생각이 있으신가요?

파라미터가 URL에 전달되지 않습니다.

아마도 다음과 같은 형식일까요: data={"params": '{"topic_id":"398"}'?

여러 가지 다른 대안을 많이 시도해 보았지만, 결국 이 방법이 효과가 있었습니다:

                         headers=headers, data={'params': '{\"topic_id\": "398"}'})```

즉, 정답은 이전 게시물(Windows 머신에서 전송할 때 따옴표를 이스케이프해야 한다고 언급한 내용)과 Arkshine의 게시물(params 키워드 인수가 아닌 data로 전달해야 한다고 지적한 내용)의 조합입니다. 다만, 이상하게 생각하는 점은 Python requests 모듈에서 params 키워드 인수의 본래 목적이 파라미터 정보를 전달하는 것이라고 생각했기 때문입니다.

작동해서 기쁩니다!

Linux (wsl)와 Windows를 모두 시도해 보았지만, 같은 문제가 발생하지 않았고 두 환경에서 모두 정상적으로 작동했습니다. :thinking:

data = {
    'params': '{"topic_id": "3"}'
}

response = requests.post(
    url="http://localhost:4200/admin/plugins/explorer/queries/4/run", 
    headers=headers, 
    data=data
)

image