I am developing a Flask application, that at the moment takes requests and answers them. However I developed it locally and it works just fine, but when trying to run it on repl.it
, it doesn't work (Requests raises "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
)
Why is that? (I know, that repl.it
uses a different IP than I use locally, but I switched them already.)
client:
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)
server:
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)
The error occurs because you are making request on address 127.0.0.1
which in case is not used by repl.it.
Make a request on the url provided by repl.it.
The url will be:
https://your-app-name.your-replit-username.repl.co/
Your code would be
import json
import requests
conv = [{'id': 1, 'key': 'get_password'}]
payload = json.dumps(conv)
res = requests.post("https://moneyserver.jgroeger.repl.co/", json=payload).json()
print(res)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.