1
leishi1313 2019-09-24 14:49:52 +08:00 via Android 1
不贴代码没法 debug,建议你查看下有没有哪个函数用了 list,dict 之类的作为默认参数
|
2
roricon 2019-09-24 14:54:31 +08:00 1
你看看爬虫采集那部分是不是没设置 timeout,爬虫被 ban 之后一直卡在那里没有及时释放内存。
|
3
liwenbest OP #coding:utf-8
from flask import Flask from flask import jsonify from flask import request import re import time,random from util import time_to_date,time_to_day import json from tyc_search import Tycsearch class Apibase: def __init__(self): self.mongodb = Mongobase(GsmongoDB) self.mongodb.connect() def get_mongoone(self,condition,tname): return self.mongodb.select(condition,tname) def get_mongoall(self,tname): return self.mongodb.all_dt(tname) def close_mongo(self): return self.mongodb.close() class ComplexEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, datetime): return obj.strftime('%Y-%m-%d %H:%M:%S') elif isinstance(obj, date): return obj.strftime('%Y-%m-%d') else: return json.JSONEncoder.default(self, obj) app = Flask(__name__) apibase = Apibase() tycseach = Tycsearch() @app.route('/cha/search', methods=['GET']) def get_tasks7(): #global m kw = request.args.get("key") kw = kw.replace(' (','(').replace(') ',')').replace(' ','') print(f'请求信息:{kw}......') try: _ = apibase.mongodb.select({'searchkey': {'=':kw}},tname=GsmongoDB['tyc_records']) if len(_)==0: dic = tycseach.search(kw) #print(dic) return json.dumps(dic,ensure_ascii=False) else: dic = _[-1] del dic['_id'] #apibase.close_mongo() return json.dumps(dic,ensure_ascii=False) except Exception as E: print(f'请求失败:原因是:{E}..') dic = {} dic['code'] = '405' dic['urlid'] = "" dic['pingfen'] = '' dic['searchkey'] = kw dic['qymc'] = '' dic['请求失败原因'] = '接口调用异常..' now_time,now_day = time_to_day(time.time()) dic['climbdate'] = now_day return json.dumps(dic,ensure_ascii=False) @app.route('/') def index(): return "Hello, World!" if __name__ == '__main__': #app.run(debug=True) app.run(host="0.0.0.0",port=8090,threaded=True)#h |
4
liwenbest OP V 站这里贴代码有些乱
|
5
ClericPy 2019-09-24 15:00:24 +08:00 1
这报错信息这么完整了, 一搜一大把啊... 写程序在初级阶段的时候, 优雅的选择往往是先搜再问
代码也没贴, 只能猜测是你爬虫或者 mongodb 那边的问题了 随手搜了次貌似是 Windows 上动态端口被你消耗完了... http://blog.zhaojie.me/2010/08/lack-of-dynamic-ports-when-frequently-open-and-close-socket.html Google 这种报错, 中文的不太好说, 但是英文的一般 stackoverflow 上肯定有答案 |
6
celeron533 2019-09-24 20:53:28 +08:00 1
这个错误一般是由于端口耗尽,很有可能是使用完成后没有正确的关闭连接
|