Cómo ejecutar consultas de Data Explorer con Python

¡Hola!

En relación con este tema: Run Data Explorer queries with the Discourse API - #27

Intenté portar el comando CURL a Python y, desde el punto de vista de la sintaxis, todo parece correcto, pero siempre obtengo un error 404. Sin embargo, al ejecutar el comando CURL, recibo un código 200. ¿Alguien de ustedes puede identificar qué estoy haciendo mal? Aquí está mi código en Python:

# Importaciones

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>'

# Funciones 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("CÓDIGO DE ESTADO: %s" % request.status_code)

send_request(ENDPOINT)

¡Gracias por la ayuda!

3 Me gusta

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 Me gusta

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

1 me gusta

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.