#Python Flask Project Deploy

15 messages · Page 1 of 1 (latest)

open siren
#

I am trying to deploy a Python Project works with Flask on Appwrite, but this is not working, domain shows 500 Error and Logs for any execution is not loading (button not working).

frigid quarry
open siren
devout fable
devout fable
frigid quarry
devout fable
#

Well, also the network tab logs

rancid trail
open siren
#

`from functools import wraps
from flask import Flask, request, jsonify
from flask_cors import CORS
from cachetools import TTLCache
import json
import asyncio
import lib2

app = Flask(name)
CORS(app)

Create a cache with a TTL (time-to-live) of 300 seconds (5 minutes)

cache = TTLCache(maxsize=100, ttl=300)

def cached_endpoint(ttl=300):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
cache_key = (request.path, tuple(request.args.items()))
if cache_key in cache:
return cache[cache_key]
else:
result = func(*args, **kwargs)
cache[cache_key] = result
return result
return wrapper
return decorator

curl -X GET 'http://127.0.0.1:3000/api/account?uid=1813014615&region=ind'

@app.route('/api/account')
@cached_endpoint()
def get_account_info():
region = request.args.get('region')
uid = request.args.get('uid')

if not uid:
    response = {
        "error": "Invalid request",
        "message": "Empty 'uid' parameter. Please provide a valid 'uid'."
    }
    return jsonify(response), 400, {'Content-Type': 'application/json; charset=utf-8'}

if not region:
    response = {
        "error": "Invalid request",
        "message": "Empty 'region' parameter. Please provide a valid 'region'."
    }
    return jsonify(response), 400, {'Content-Type': 'application/json; charset=utf-8'}

try:
    return_data = asyncio.run(lib2.GetAccountInformation(uid, "7", region, "/GetPlayerPersonalShow"))

    # Patch: Replace clothes with equipedSkills if present
    if "profileInfo" in return_data:
        profile = return_data["profileInfo"]
        if "equipedSkills" in profile:
            profile["clothes"] = profile["equipedSkills"]
            del profile["equipedSkills"]

    formatted_json = json.dumps(return_data, indent=2, ensure_ascii=False)
    return formatted_json, 200, {'Content-Type': 'application/json; charset=utf-8'}
except Exception as e:
    return jsonify({
        "error": "Server error",
        "message": str(e)
    }), 500, {'Content-Type': 'application/json; charset=utf-8'}

if name == 'main':
app.run(port=3000, host='0.0.0.0', debug=True)`

Here is my main code (app.py)

open siren
rancid trail