【发布时间】:2021-10-01 03:56:08
【问题描述】:
我正在开发一个 Flask 应用程序,目前它接受请求并回答它们。但是我在本地开发它并且它工作得很好,但是当尝试在repl.it上运行它时,它不起作用(请求引发“Winerror 10060”:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)
这是为什么呢? (我知道,repl.it 使用的 IP 与我在本地使用的不同,但我已经切换了它们。)
客户:
import json
import requests
conv = [{'id': 1, 'key': 'get_password'}]
payload = json.dumps(conv)
res = requests.post("http://127.0.0.1:5000", json=payload).json()
print(res)
服务器:
from flask import Flask, request
import json
app = Flask(__name__)
@app.route('/', methods = ['POST'])
def home():
jsondata = request.get_json()
data = json.loads(jsondata)
#stuff happens here that uses the data
print(data)
result = {'response': True}
return json.dumps(result)
if __name__ == '__main__':
app.run(host = "0.0.0.0", port = 5000)
【问题讨论】:
-
“它不起作用” 不是有用的错误描述。
-
编辑了错误信息
-
每次尝试发出请求时都会出错。如果没有,请检查您的互联网连接。也可以使用命名参数
app.run(host"0.0.0.0", port=5000) -
是的,它确实给出了错误,我的互联网工作正常。我认为它可能是阻止连接的代理或防火墙(在 repl.it 上),但我不知道发生这种情况的情况。已编辑命名参数。
标签: python flask server client