OSError:[WinError 6]句柄无效

时间:2019-07-11 07:40:52

标签: python python-3.x flask

我已经创建了API并在angular项目中使用了

当我可以从angular python API时,收到一条错误消息。我尝试了多种选择,但无法正常工作。您能帮我了解我在做什么错

import json
import pyodbc

from flask import Flask, jsonify, Response, url_for
from flask_cors import CORS, cross_origin
from pynput.keyboard import Key, Controller
from werkzeug.utils import redirect

from Flask.venv.Lib import os


app = Flask(__name__)
CORS(app)


# API to get data from database and display on application
@app.route('/config')
@cross_origin()
def home():
    alldata = []
    con = pyodbc.connect(
        "DRIVER={SQL Server};server=vpna-qat-dbw02.AD-DEV.issgovernance.com,4400;database=Katalon;uid=automationui;pwd=automationui")

    cur = con.cursor()

    result = cur.execute("select `enter code here`* from dbo.Project")

    items = []
    for row in result:
        items.append({'id': row[0], 'suitename': row[1], 'suitepath': row[2]})

    cur.close()
    con.close()

    return (json.dumps(items))


# API to execute the script
keyboard = Controller()

@app.route('/config/<path:name>')
@cross_origin()
def home1(name):
    open(os.system("start cmd"))
    keyboard.type(name)
    keyboard.press(Key.enter)
    keyboard.type("exit")
    keyboard.press(Key.enter)
    return name


# API to bind above both APIs
@app.route('/config/<path:name>')
@cross_origin()
def user(value):
    if value != '':
        return redirect(url_for('home'))
    if value == 'librarion':
        return redirect(url_for('home1(value)'))


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

当我从角度代码调用API时,将显示以下错误消息。

Traceback (most recent call last):
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\app.py", line 2328, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\app.py", line 2314, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\app.py", line 1760, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\_compat.py", line 36, in reraise
raise value
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\app.py", line 1834, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\app.py", line 1737, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\_compat.py", line 36, in reraise
raise value
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask\app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\sapkpra\PycharmProjects\Test1\venv\lib\site-packages\flask_cors\decorator.py", line 128, in wrapped_function
resp = make_response(f(*args, **kwargs))
File "C:\Users\sapkpra\PycharmProjects\Test1\Flask\FinalAPI.py", line 44, in home1
open(os.system("start cmd"))
OSError: [WinError 6] The handle is invalid

0 个答案:

没有答案