Comment exécuter des requêtes Data Explorer avec Python

Salut !

Concernant ce sujet : Run Data Explorer queries with the Discourse API - #27

J’ai essayé de convertir la commande CURL en Python et, du point de vue de la syntaxe, tout semble correct, mais je reçois systématiquement une erreur 404, alors que lorsque j’exécute la commande CURL, je reçois un code 200. L’un de vous pourrait-il identifier ce que je fais de mal ? Voici mon code Python :

# Imports

import requests
import json

# Constantes

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

# Fonctions principales

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("CODE D'ÉTAT : %s" % request.status_code)

send_request(ENDPOINT)

Merci pour votre aide !

3 « J'aime »

You will need to put the api credentials in with the headers.

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

And for the actual request you might need to specify it like this:

requests.post(endpoint, headers=headers)
6 « J'aime »

Perfectly thanks that worked! Thanks a lot @blake for help!

1 « J'aime »

A post was merged into an existing topic: Creating a topic via the API using Node.js

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