亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

API會在一段時間后停止工作

API會在一段時間后停止工作

長風秋雁 2021-04-06 17:14:39
我編寫了一個API,該API以目錄作為輸入,它將將該文件夾(及其子文件夾)中的每個文本文件(.txt)加載到Postgres DB中。該API適用于一些文件(大約3個),但是當它開始“讀取”第四個文件時,無論文件是什么,程序都會崩潰。我什至將文件分成三個部分,API仍然停止。我也得到一個 curl: (52) Empty reply from server這是代碼:@apiR2A.route('/api/lectura', method=['POST'])def read_txt():    #get_postgres_connection()    arch = [] #list of succesfully read files    arch_err = [] #list of files with errors    con = create_connection() #creating connection with db    archivos = request.query.archivos    for root, dirs, files in os.walk(archivos):        for file in files: #looping through all the files inside root            if file.endswith(".txt"): #only looking for text files                #creating dataframe                df = pd.read_csv(os.path.join(root, file), encoding="utf-8", sep="|", header=None)                 if len(df.columns) is not 12: #verifying num of columns                    print("WARNING: File {} has wrong format\n".format(os.path.join(root, file)))                    arch_err.append(file)                    continue                sleep(10)                df.columns = ["1","2","3","4","5","6","7","8","9","10","11","12"] #setting column names                print('Reading: {}'.format(os.path.join(root, file)))                #adding df to db                df.to_sql('FBDClientesCuentas',                      con,                      if_exists='append',                      index=False)                print('{} succesfully added to db.\n'.format(file))                sleep(5)                arch.append(file)    if len(arch) > 0:        print('Files loaded to database:')        for x in arch:            print(x)    if len(arch_err) > 0:        print('\nUnread files:')        for x in arch_err:            print(x)編輯:我忽略了似乎是問題的根源,API的運行方式如下:if __name__ == '__main__':    apiR2A.run( server='tornado', host='0.0.0.0', port=3000, reloader=True)問題出在我選擇運行API的服務器上
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 323 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號