我已经在 pythonanywhere 上部署了成功运行的 python Flask 应用程序。 仅显示主页,但当我提交表单时,它抛出内部服务器错误。
可能是什么情况。检查控制台网络,我使用的请求链接没有被访问,并且出现错误。
我已在 virtualenv 中成功安装了项目的 requests 和 BeautifulSoup 依赖项。
这是代码
from flask import Flask,render_template
from flask import request
#lets do the scraping here
import requests
from bs4 import BeautifulSoup
app=Flask(__name__)
@app.route('/',methods=['GET','POST'])
def index():
if request.method== "GET" :
return render_template('home.html',result="")
else:
result=requests.post("jobkhulyo.com/")
soup1=BeautifulSoup(result.content)
return render_template('home.html',result=soup1);
if __name__=="__main__":
app.run(debug=True)
GET 方法运行良好,但对于 POST 方法,它会引发内部服务器错误。 Home.html是模板目录中的模板文件。在 POST 方法中加载相同的模板,但在提交表单时加载一些值。
最佳答案
传递给请求的 URL 必须以某种方案开头,例如 http://
或 https://
。您的 URL 没有,因此它会引发 MissingScheme
异常,该异常准确地解释了问题所在。
MissingSchema: Invalid URL 'jobkhulyo.com': No schema supplied. Perhaps you meant http://jobkhulyo.com?
按照提示,向 http://jobkhulyo.com
发出请求。
当在 Debug模式下本地运行服务器时,Flask 将显示发生的错误的回溯。在生产中,它将显示 500 错误,但仍记录回溯。启用日志记录以查看这些错误,如 Flask application traceback doesn't show up in server log 中所述。 .
关于部署在 pythonanywhere 上的 Python Flask 应用程序提交时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41148373/