Como executar consultas do Data Explorer com Python

Olá!

Sobre este tópico: Run Data Explorer queries with the Discourse API - #27

Tentei portar o comando CURL para Python e, do ponto de vista da sintaxe, tudo parece estar correto, mas estou recebendo 404 todas as vezes. No entanto, ao executar o comando CURL, recebo 200. Alguém consegue identificar o que estou fazendo de errado? Aqui está meu código em Python:

# Imports

import requests
import json

# Constants

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

# Core Functions

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)

Obrigado pela ajuda!

3 curtidas

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 curtidas

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

1 curtida

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.