iam not web devoloper making a simple flask app with pyscript woring or bud afterthis error comein
JsException(PythonError: JsException: Error: Object has already been destroyed The object was of type "coroutine" and had repr "" )
flask code
from flask import Flask
from flask import render_template
from flask import request, jsonify
app=Flask(__name__,template_folder='templates')
@app.route('/')
def Dta():
if request.is_json:
data = 'data to response'
return jsonify({'data':data})
return render_template('index.html')
if __name__ == '__main__':
app.run()
HTML code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<title>Document</title>
</head>
<body>
<p>Cripto</p>
<p id = 'data'>/</p>
<py-script>
from pyodide.http import pyfetch
async def make_requst(url, method, headers=None):
if not headers:
headers={
'X-Requested-With' : 'XMLHttpRequest',
'Content-Type' : 'application/json'
}
responce = await pyfetch(url=url, method= method,headers = headers)
return await responce.json()
async def get_data():
data = await make_requst(url='/', method='GET')
pyscript.write('data', data['data'])
get_data()
</py-script>
</body>
</html>
-----------------------------------------------------------------
CodePudding user response:
Error: Object has already been destroyed The object was of type "coroutine" and had repr ""
That error means that your code is using asynchronous events and you have not imported a required Python package to support that. Anytime you use the keywords async and await in PyScript, you must import a supporting package.
In your PyScript code add:
import asyncio