ABOUT   FEATURES   REVIEWS   DOWNLOAD   MEDIA   CONTACT  PLAY NOW

Unable to Configure API

  • 4 Replies
  • 81 Views
*

jamesmilleree

  • *
  • 1
  • +0/-0
  • Ludo King
Unable to Configure API
« on: November 15, 2023, 10:59:22 AM »
Hi,

I am doing Python certification course and building web application, I am trying to integrate Ludo Kind API but it's getting- Error: "Failed to validate API key. Status code: 401. I don't know why it's showing this error. Although, I made it very carefully by following step-by-step process- https://github.com/ChrisRu/ludo-api.

Here is the code I am using-

import requests
from flask import Flask, jsonify

app = Flask(__name__)

# Assume you have a function to configure the Ludo King API
def configure_ludo_king_api(api_key, base_url):
    try:
        # Make a request to the Ludo King API to validate the key
        response = requests.get(f"{base_url}/validate?key={api_key}")

        # Check if the API key is valid
        if response.status_code == 200:
            return True
        else:
            raise Exception(f"Failed to validate API key. Status code: {response.status_code}")

    except requests.exceptions.RequestException as e:
        raise Exception(f"Error connecting to Ludo King API: {e}")

# Example endpoint to configure Ludo King API in your web application
@app.route('/configure-ludo-king-api/<api_key>')
def configure_ludo_king(api_key):
    try:
        # Replace 'YOUR_LUDO_KING_BASE_URL' with the actual base URL of Ludo King API
        ludo_king_base_url = 'YOUR_LUDO_KING_BASE_URL'
       
        # Call the function to configure Ludo King API
        if configure_ludo_king_api(api_key, ludo_king_base_url):
            return jsonify({"success": True, "message": "Ludo King API configured successfully"})
        else:
            return jsonify({"success": False, "message": "Failed to configure Ludo King API"})

    except Exception as e:
        return jsonify({"success": False, "error": str(e)})

if __name__ == '__main__':
    app.run(debug=True)



Any help will highly be appreciated.
Thanks