Reputation: 41
from quart import Quart, request, render_template, jsonify
import json
import os, sys
import pandas as pd
import requests
import asyncio
from pylon.model.db_models import RawFiles
from pylon.orm import db
app = Quart(__name__)
@app.route('/upload', methods=['POST'])
async def handle_form():
f = await request.files['filename']
f.save(f.filename)
data = pd.read_csv(f.filename)
data.to_json("json_data.json")
data = pd.read_json("json_data.json")
os.remove("json_data.json")
os.remove(f.filename)
print(type(data))
print(data)
return ""
@app.route("/")
async def index():
return await render_template('upload.html')
if __name__ == "__main__":
app.run(host="bheem11.arch.des.co", port=5043, debug = True)
I am getting one error described in title. I am working in quartz framework in python. Hoping for proper solution. Actually i am getting coroutine error when @app.route("/upload", methods = "post") execute.
Upvotes: 4
Views: 3920
Reputation: 7039
This line await request.files['filename']
should be (await request.files)['filename']
. Without the parenthesis everything to the right of await
is evaluated first, which results in the attempt to subscribe (['filename']
operation) the files
attribute. This doesn't work as the files
attribute returns a coroutine - which is not subscriptable. There is more on this in the Quart documentation.
Upvotes: 5