请求的 URL 不允许使用该方法
The method is not allowed for the requested URL
当我通过 Facebook Messenger 访问时出现此错误?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
这是代码
网络应用程序
from flask import Flask
from flask import request
from flask import render_template, redirect, url_for, request,jsonify,
app = Flask(__name__, template_folder='./')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/prediction', methods=['POST', 'GET'])
def prediction():
if request.method == 'POST':
if request.form != None and 'message' in request.form:
msg = request.form['message']
response = pred(str(msg))
return jsonify(response)
else:
return render_template('index.html')
if __name__ == '__main__':
app.debug = True
app.run()
index.html
<html>
<head>
<title>Upload</title>
</head>
<body>
<p1>
Yooooo Tensorflow thoooo
</p1>
<form action="{{ url_for('prediction') }}" method='POST' >
<input type=text name="message" value="" maxlength="100">
<input type="submit" value="submit" >
</form>
</body>
</html>
我正在尝试 运行 通过我使用 heroku 连接的 Facebook Messenger
由于 POST 和 GET 在您看来都已启用,这很可能是 CORS 错误
按照说明 here 允许 apache 的跨源请求
或者 here 如果您的 Web 服务器是 nginx
例如,我的应用程序使用 apache 在 ubuntu 16.04 上托管,我 运行
sudo nano /etc/apache2/sites-available/000-default.conf
在终端上
我编辑我的服务器配置并添加 Header set Access-Control-Allow-Origin "*" 以允许跨源请求。星号是通配符,表示我允许来自任何站点的请求,您可以将其替换为您想要允许的站点
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
Header set Access-Control-Allow-Origin "*"
#Include conf-available/serve-cgi-bin.conf
WSGIScriptAlias / /var/www/html/myapp.wsgi
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mysite.com [OR]
RewriteCond %{SERVER_NAME} =mysite.com.info
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
忽略将对我的应用程序的请求重定向到 https 的重写规则。你只需要添加 Header set Access-Control-Allow-Origin "*"
当我通过 Facebook Messenger 访问时出现此错误?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>
这是代码
网络应用程序
from flask import Flask
from flask import request
from flask import render_template, redirect, url_for, request,jsonify,
app = Flask(__name__, template_folder='./')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/prediction', methods=['POST', 'GET'])
def prediction():
if request.method == 'POST':
if request.form != None and 'message' in request.form:
msg = request.form['message']
response = pred(str(msg))
return jsonify(response)
else:
return render_template('index.html')
if __name__ == '__main__':
app.debug = True
app.run()
index.html
<html>
<head>
<title>Upload</title>
</head>
<body>
<p1>
Yooooo Tensorflow thoooo
</p1>
<form action="{{ url_for('prediction') }}" method='POST' >
<input type=text name="message" value="" maxlength="100">
<input type="submit" value="submit" >
</form>
</body>
</html>
我正在尝试 运行 通过我使用 heroku 连接的 Facebook Messenger
由于 POST 和 GET 在您看来都已启用,这很可能是 CORS 错误
按照说明 here 允许 apache 的跨源请求
或者 here 如果您的 Web 服务器是 nginx
例如,我的应用程序使用 apache 在 ubuntu 16.04 上托管,我 运行
sudo nano /etc/apache2/sites-available/000-default.conf
在终端上
我编辑我的服务器配置并添加 Header set Access-Control-Allow-Origin "*" 以允许跨源请求。星号是通配符,表示我允许来自任何站点的请求,您可以将其替换为您想要允许的站点
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
Header set Access-Control-Allow-Origin "*"
#Include conf-available/serve-cgi-bin.conf
WSGIScriptAlias / /var/www/html/myapp.wsgi
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mysite.com [OR]
RewriteCond %{SERVER_NAME} =mysite.com.info
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
忽略将对我的应用程序的请求重定向到 https 的重写规则。你只需要添加 Header set Access-Control-Allow-Origin "*"