我是创建API的新手。但我创建了一个类似以下代码的代码:
app = Flask(__name__)
@app.route("/",methods=['GET','POST'])
def hello():
try :
with open('logs.txt','a') as f :
f.write(f"{datetime.now()}\n")
except Exception as e :
print(str(e))
value = request.args.get('symbol')
result = database.get_symbol(value)
return jsonify(result)
if __name__ == '__main__':
app.run(debug=False)因此,我有一个VPS (虚拟专用服务器)上的windows7,我正在尝试运行我的flask应用程序在它。但当我运行它时,代码将如下所示:
main.py:443: DeprecationWarning: use options instead of chrome_options
return webdriver.Chrome(chrome_options=option)
* Serving Flask app "main" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)但当我在我的服务器上运行它,并尝试使用我自己的个人计算机访问它时,代码如下:
curl [ip_address]:5000/?symbol=value 它给了我一个错误:
curl: (7) Failed to connect to [IP] port 5000: Connection refused如何使用此API?
我可以在开发者模式下部署它吗?
发布于 2019-09-28 11:36:53
127.0.0.1是您自己的IP地址,只能从该PC访问。
if __name__ == '__main__':
app.run(debug=False, host=<VPS's IP address>)您可以编写0.0.0.0,并在从外部连接时指定VPS的IP地址,而不是分配。
https://stackoverflow.com/questions/58143024
复制相似问题