每當我嘗試運行我的燒瓶應用程式時,我都會收到此錯誤:
requests.exceptions.ConnectionError
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000):
Max retries exceeded with url: //chain (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001EECEBA9E10>:
Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
我運行應用程式的步驟是:設定 FLASK_APP=hello
燒瓶運行
任何人都可以幫忙嗎?
這是我的 view.py 檔案
import datetime
import json
import requests
from flask import render_template, redirect, request
from app import app
# The node with which our application interacts, there can be multiple
# such nodes as well.
CONNECTED_NODE_ADDRESS = "http://127.0.0.1:8000/"
posts = []
def fetch_posts():
"""
Function to fetch the chain from a blockchain node, parse the
data and store it locally.
"""
get_chain_address = "{}/chain".format(CONNECTED_NODE_ADDRESS)
response = requests.get(get_chain_address)
if response.status_code == 200:
content = []
chain = json.loads(response.content)
for block in chain["chain"]:
for tx in block["transactions"]:
tx["index"] = block["index"]
tx["hash"] = block["previous_hash"]
content.append(tx)
global posts
posts = sorted(content, key=lambda k: k['timestamp'],
reverse=True)
@app.route('/')
def index():
fetch_posts()
return render_template('index.html',
title='YourNet: Decentralized '
'content sharing',
posts=posts,
node_address=CONNECTED_NODE_ADDRESS,
readable_time=timestamp_to_string)
@app.route('/submit', methods=['POST'])
def submit_textarea():
"""
Endpoint to create a new transaction via our application.
"""
post_content = request.form["content"]
author = request.form["author"]
post_object = {
'author': author,
'content': post_content,
}
# Submit a transaction
new_tx_address = "{}/new_transaction".format(CONNECTED_NODE_ADDRESS)
requests.post(new_tx_address,
json=post_object,
headers={'Content-type': 'application/json'})
return redirect('/')
def timestamp_to_string(epoch_time):
return datetime.datetime.fromtimestamp(epoch_time).strftime('%H:%M')
uj5u.com熱心網友回復:
這可能由于各種原因而發生。也許您嘗試運行的埠正在被另一個應用程式使用。嘗試下面的結構來更改燒瓶正在運行的埠。
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'something'
app.run(host='127.0.0.1', port=5000)
嘗試使用不同的埠,如 5000 或 8080。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/380538.html
