简体   繁体   English

Python、Flask:方法不允许,请求的方法不允许 URL

[英]Python, Flask: Method Not Allowed, The method is not allowed for the requested URL

So I am trying to launch a node to run a distributed ledger but every time I want to run it I get this message所以我试图启动一个节点来运行一个分布式分类帐,但每次我想运行它时,我都会收到这条消息

172.16.1.109 - - [30/Nov/2021 14:38:45] "GET /transactions/new HTTP/1.1" 405 - See here for the error 172.16.1.109 - - [2021 年 11 月 30 日 14:38:45] “GET /transactions/new HTTP/1.1” 405 -请参阅此处了解错误

Here is some of my code:这是我的一些代码:

from uuid import uuid4
from flask import Flask as Flask
from flask import send_file as send_file
from flask import request as request
from flask import jsonify as jsonify
import networkx as nx
import matplotlib.pyplot as plt
import os
import sys
# custom classes
from ledger.node import node
from ledger.util import Util
app = Flask(__name__)
@app.route('/node/register_neighbours', methods=['GET', 'POST'])
def register_new_node():
    print("register_new node")
    response = node.register_neighbours(request.get_json())
    return jsonify(response), 201
@app.route('/transactions/new', methods=['GET', 'POST'])
def make_transaction():
    request_params = request.get_json(force=True)
    response = node.ledger.make_transaction(request.form.get('sending_address'),
                                            request.form.get('receiving_address'),
                                            request.form.get('value'))
    return jsonify(response), 201
@app.route('/wallet/balance', methods=['GET', 'POST'])
def wallet_balance():
    address = request.form.get('address')
    if address in node.wallet.getWalletAddresses():
        return "[+] Wallet balance for address [%s] is: %s " % (address, node.wallet.getbalance(address))
    else:
        return "[-] This node's wallet has no such address: %s" % address
@app.route('/wallet/addresses', methods=['GET', 'POST'])
def wallet_addresses():
    return "[+] Wallets addresses of this node: " + str(node.wallet.getWalletAddresses().keys())
@app.route('/dag', methods=['GET', 'POST'])
def show_DAG():
    serializable_format = node.getTangleAsJSONdict()
    node.writeTangleToJSONfile()
    return jsonify(serializable_format), 201
# return jsonify(node.tangle.DAG), 201
    # problem with the original code was that, DAG dictionary has Transaction Objects as values,
    # and those are not serializable as JSON objects.
    # return jsonify(node.DAG), 201
@app.route('/dag/png', methods=['GET', 'POST'])
def get_DAG_as_png():
    serializable_format = node.getTangleAsJSONdict()
    node.writeTangleToJSONfile()

You've specified that the only acceptable method for that endpoint is POST :您已指定该端点唯一可接受的方法是POST

@app.route('/transactions/new', methods=['POST'])

You can edit this to include GET as an item in the array, however this will not work, as it's expecting form data to be supplied.您可以编辑它以将GET作为一个项目包含在数组中,但这不起作用,因为它期望提供表单数据。

As you're attempting to access from a browser, you'll always be using a GET request and wont be able to supply the form data.当您尝试从浏览器访问时,您将始终使用GET请求并且无法提供表单数据。 I recommend a tool such as Postman or Insomnia to generate HTTP requests when testing.我推荐使用 Postman 或 Insomnia 等工具在测试时生成 HTTP 请求。

With a tool such as these, you can add the data that needs to be supplied, in your case the fields sending_address , recieving_address and value .使用诸如此类的工具,您可以添加需要提供的数据,在您的情况下是字段sending_addressrecieving_addressvalue

In a web app, you'll need to include a form that has those fields for it work.在 web 应用程序中,您需要包含一个包含这些字段才能工作的表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python flask flask不允许的方法所请求的URL不允许使用该方法 - Python flask Method Not Allowed The method is not allowed for the requested URL Python Flask:错误“请求的 URL 不允许使用该方法” - Python Flask: Error "The method is not allowed for the requested URL" 不允许的方法 请求的 URL 不允许使用该方法。 在 DELETE 方法烧瓶上 - Method Not Allowed The method is not allowed for the requested URL. on DELETE Method Flask Flask 错误:“方法不允许 请求的 URL 不允许该方法” - Flask Error: “Method Not Allowed The method is not allowed for the requested URL” Flask 错误:“方法不允许 请求的 URL 不允许该方法” - Flask Error: "Method Not Allowed The method is not allowed for the requested URL" Flask 错误:方法不允许 请求的 URL 不允许该方法 - Flask error: Method Not Allowed The method is not allowed for the requested URL Flask 错误:方法不允许 请求的 URL 不允许该方法 - Flask error : Method Not Allowed The method is not allowed for the requested URL 所请求的URL不允许使用该方法-Flask + HTML - The method is not allowed for the requested URL - Flask + HTML Flask - POST - 请求的URL不允许使用该方法 - Flask - POST - The method is not allowed for the requested URL 所请求的URL不允许使用该方法。 在烧瓶 - The method is not allowed for the requested URL. in Flask
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM