Python で Data Explorer クエリを実行する方法

こんにちは!

このトピックについてです:Run Data Explorer queries with the Discourse API - #27

cURL コマンドを Python に移植しようと試みました。構文の観点からはすべて問題なさそうに見えるのですが、常に 404 エラーが発生します。一方、cURL コマンドを実行すると 200 が返ってきます。何が間違っているか分かる方がいらっしゃいますか?私の Python コードは以下の通りです:

# インポート

import requests
import json

# 定数

ENDPOINT = 'https://community.myCompanyName.com/admin/plugins/explorer/queries/73/run'
API_KEY = '<the_api_key>'
API_USERNAME = '<my_discourse_username>'

# コア関数

def send_request(endpoint):

    api_keys = {'Api-Key': API_KEY, 'Api-Username': API_USERNAME}
    headers = {'Content-Type': 'multipart/form-data'}
    request = requests.post(endpoint, api_keys, headers)
    print("STATUS CODE: %s" % request.status_code)

send_request(ENDPOINT)

ご協力ありがとうございます!

「いいね!」 3

API 認証情報をヘッダーに含める必要があります。

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

実際のリクエストでは、以下のように指定する必要があるかもしれません。

requests.post(endpoint, headers=headers)
「いいね!」 6

完璧です、ありがとうございます!うまくいきました!@blake さんのサポートに心から感謝します!

「いいね!」 1

投稿が既存のトピックにマージされました:Node.js を使用した API によるトピックの作成

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.