spec-first / connexion

Connexion is a modern Python web framework that makes spec-first and api-first development easy.
https://connexion.readthedocs.io/en/latest/
Apache License 2.0
4.48k stars 762 forks source link

Issue in executing the main.py #1413

Closed SYKAMR closed 3 years ago

SYKAMR commented 3 years ago

Description

runfile('C:/Users/XXXXXX/XXXXXXX/XXXXX/XXXXX/XXXXX', wdir='C:/Users/XXXXX/XXXXX/XXXXXR/XXXXX/XXXXX/src') Reloaded modules: api_data_provider The swagger_ui directory could not be found. Please install connexion with extra install: pip install connexion[swagger-ui] or provide the path to your local installation by passing swagger_path=

The swagger_ui directory could not be found. Please install connexion with extra install: pip install connexion[swagger-ui] or provide the path to your local installation by passing swagger_path=

SystemExit: 1

Expected behaviour

Actual behaviour

Steps to reproduce

Additional info:

Spyder console is showing the mentioned issue, installed all the modules required. Please do the needful. Output of the commands:

Ruwann commented 3 years ago

Hi @SYKAMR , could you provide your main.py and all your installed packages (the output of pip freeze)?

SYKAMR commented 3 years ago

import json import os import flask from flask import render_template, request,Flask from flask import request, jsonify import ast from getrequestDetails import from check_user import from checkVnV_response import * from flask import after_this_request import connexion from flask import Flask

Create the application instance

app = connexion.App(name, specification_dir='./') app.app = Flask(name, static_url_path='/services/eln/register/static')

Read the swagger.yml file to configure the endpoints

app.add_api('swagger.yaml')

app.app.config["JSON_SORT_KEYS"]=False app.app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 app.app.secret_key = 'development key'

app.app = Flask(name,static_folder='/app/static')

list_current_file = []

def get_input_vnv(sample_id): print("This is sample_id....",sample_id)

sample_id = "sample:a2b07aae-9c4d-4ce6-ab88-fe593b6689ec"

url = "https://devstaging.snbstg5bup.perkinelmercloud.com/api/rest/v1.0/entities/" + sample_id + "/export?format=mol"

payload = {}
headers = {
    'x-api-key': 'v1/ax6PK9N35g83mRyeBzZtE6NMbEDrqrKLMwb3LV6B4ucz1ByUyn3+1kc3fC2C8FzD4vQ==',
}

response = requests.request("GET", url, headers=headers, data=payload, verify=False)
print("response from get_input vnv....",response.text)
# os.remove("static/sample.mol")
# os.remove("static/Vnv.png")
t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
image_name = ("image" + timestamp+".png")
global list_current_file
list_current_file.append(image_name)
mol_name= ("mol" + timestamp+".mol")
list_current_file.append(mol_name)
with open('static/'+mol_name, "w+") as f:
    print("image file  modified")
    f.write(response.text)
m = Chem.MolFromMolFile('static/'+ mol_name)
Draw.MolToFile(m, 'static/'+image_name)
return response.text,image_name

@app.route('/services/eln/register/debugSignalAction', methods=['POST', 'GET']) def debug_signalDetails(): dict_rep = {} try: dict_rep["headers"] = dict(request.headers) except: dict_rep["headers"] = {}

try:
    dict_rep["url"] = request.url
except:
    dict_rep["url"] = ""
try:
    dict_rep["ip_address"] = request.remote_addr
except:
    dict_rep["ip_address"] = ""
try:
    dict_rep["request_method"] = request.method
except:
    dict_rep["request_method"] = ""

try:
    dict_rep["query_parameter"] = request.args.to_dict()
except:
    dict_rep["query_parameter"] = ""

try:
    dict_rep["path_parameter"] = request.path
except:
    dict_rep["path_parameter"] = ""

try:
    dict_rep["data"] = request.form.to_dict()
except:
    dict_rep["data"] = {}

return dict_rep

@app.route('/services/eln/register/registrationPreCheck', methods=['POST','GET']) def signalDetails(): sample_id,user_id,origin,url = request_details(request) print("######################",sample_id,user_id,origin,url) print(read(user_id,origin))

sample_id ="sample:60c7f825-2d0d-473a-957a-52db7ef62517"

# user_id =106
# origin = "https://devstaging.snbstg5bup.perkinelmercloud.com"
# print(read(user_id, origin))

global list_current_file
# right_image_name= "Vnv.png"
respnse_strct,filename=get_input_vnv(sample_id)
left_image_name = filename
list_current_file.append(left_image_name)
stereoisomer_code,stereoisomer_name,error_msg,vnv_modification,right_flnam_rep,modified_strct= vnvresponse(respnse_strct)
print("^^^^^^",type(modified_strct),"^^^^",modified_strct)
if len(vnv_modification) !=0:
    modification_msg=vnv_modification[0]
    right_image_name=right_flnam_rep
    list_current_file.append(right_image_name)
    uniquness_check, uc_status_code = uc_response(modified_strct)
elif  len(vnv_modification) == 0:
    modification_msg = "There are no errors or modifications"
    right_image_name = filename
    list_current_file.append(right_image_name)
    uniquness_check,uc_status_code = uc_response(respnse_strct)
# print("....from main...",uniquness_check)
list_structure = []
count_struct = 0
unqc_check = ""
if uc_status_code == 200:
    if uniquness_check["hitCount"] != 0:
        # response_uc_sorted = sorted(uniquness_check["matches"], key=lambda k: k['matchType'])
        # response_uc_sorted_exact=
        # response_uc_sorted_stereoIsomerCode
        response_uc_sorted= sorted(uniquness_check["matches"], key=lambda e: (e['matchType'], e['parentNumber']))
        print("response_uc_sorted...",response_uc_sorted)
        for i in response_uc_sorted:
            dict_structure = {}
            dict_structure["matchType"] = i["matchType"]
            dict_structure["parentNumber"]=i["parentNumber"]
            dict_structure["stereoIsomerCode"] = i["stereoIsomerCode"]
            dict_structure["structureComment"] = i["structureComment"]
            with open("static/sample_" + str(count_struct) + ".mol", "w+") as f:
                f.write(i["matchStructure"])
            list_current_file.append("sample_"+str(count_struct) + ".mol")
            m = Chem.MolFromMolFile("static/sample_" + str(count_struct) + ".mol")
            Draw.MolToFile(m, "static/Vnv_" + str(count_struct) + ".png")
            dict_structure["matchStructure"] = "Vnv_" + str(count_struct) + ".png"
            list_current_file.append(dict_structure["matchStructure"])
            count_struct = count_struct + 1
            list_structure.append(dict_structure)
        print("...",list_structure)
        values_of_matchtype = [a_dict["matchType"] for a_dict in list_structure]
        print("Value for match type..",values_of_matchtype)

        if values_of_matchtype.count("EXACT") == 1 and values_of_matchtype.count("STEREOISOMER") == 0:
            unqc_check = "Your structure has an exact match."
        elif values_of_matchtype.count("EXACT") == 1 and values_of_matchtype.count("STEREOISOMER") >= 1:
            unqc_check = "Your structure has an exact match but also has stereoisomer matches."
        elif values_of_matchtype.count("EXACT") >= 1:
            unqc_check = "Your structure has more than one exact match, please request a curation to address duplicates prior to registration."
        elif values_of_matchtype.count("EXACT") == 0 and values_of_matchtype.count("STEREOISOMER") == 0:
            unqc_check = "Your structure is unique."
        elif values_of_matchtype.count("EXACT") == 0 and values_of_matchtype.count("STEREOISOMER") >= 1:
            unqc_check = "Your structure is unique but also has stereoisomer matches."
        elif values_of_matchtype.count("EXACT") == 0 and values_of_matchtype.count("STEREOISOMER") >= 0:
            list_structure=[]
            dict_0={}
            dict_0['StructureId'] = "Drawn Structure"
            dict_0['MF'] = None
            dict_0['MW'] = None
            dict_0['stereoIsomerCode'] = stereoisomer_code
            dict_0['Comment'] = ""
            dict_0['matchStructure'] = right_image_name
            list_structure.append(dict_0)

    else:
        list_structure=[]
        dict_0={}
        dict_0['parentNumber'] = "Drawn Structure"
        dict_0['MF'] = None
        dict_0['MW'] = None
        dict_0['stereoIsomerCode'] = stereoisomer_code
        dict_0['Comment'] = None
        dict_0['matchStructure'] = right_image_name
        list_structure.append(dict_0)
        unqc_check="There is no structure found in uniqueness check"

else:
    unqc_check = uniquness_check

code = str(stereoisomer_code) + "-" + str(stereoisomer_name)
print("...main file..",stereoisomer_code,error_msg)

@after_this_request
def remove_file(response):
    ext = [".png", ".mol"]
    global list_current_file
    try:
        files_in_dir = os.listdir("static")
        filtered_img_mol = [file for file in files_in_dir if file.endswith(tuple(ext))]
        files_to_remove=[x for x in filtered_img_mol if x not in list_current_file]
        for file in files_to_remove:
            os.remove("static/" + file)
        list_current_file=[]
    except Exception as e:
        list_current_file=[]
        print(e)

    return response

#return app.send_static_file('pre_check_form.html', left_image=left_image_name, right_image=right_image_name,code= code,error=modification_msg,check=list_structure,sweetalert="Registration Pre-Check",uc_msg=unqc_check)

return render_template('pre_check_form.html', left_image=left_image_name, right_image=right_image_name,code= code,error=modification_msg,check=list_structure,sweetalert="Registration Pre-Check",uc_msg=unqc_check)

@app.route('/services/eln/user/bearerTokenExchange.html') def bearerTokenExchange_user_html(): return render_template('bearerTokenExchange.html')

@app.route('/services/eln/user/bearerTokenExchange') def bearerTokenExchange():

ToDo: Insert bearerTokenExchange code here

return jsonify({"request.path": request.path}, {"request.args": request.args}), 200

If we're running in stand alone mode, run the application

if name == 'main': app.run(host='0.0.0.0', port=5000, debug=True) modules capture

SYKAMR commented 3 years ago

Hi, Is the data sufficient for your reference. Let me know if need anything from my end

RobbeSneyders commented 3 years ago

Hi @SYKAMR, you didn't provide the installed packages.

But from your first error message, it seems like your issue should be fixed by installing connexion with the swagger-ui extra: pip install connexion[swagger-ui]

If this doesn't fix your issue, please provide a minimal working example we can use to reproduce the issue.