我正在尝试在PythonAnywhere上传我的网络应用程序,但我无法做到这一点。我尝试了很多方法,并在谷歌搜索但我无法解决它。请告诉我我缺少什么或者我应该在这里添加更多信息。我还从PythonAnywhere添加了错误日志。如果可能的话,请有人向我解释错误,因为我做错了。
我的文件结构
|-mysite/
flask_app.py
|-templates/
index.html
run.py
from flask import render_template
from bs4 import BeautifulSoup, element
import urllib2
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
i=1
count =1
items = []
heads = []
bodys = []
writers = []
dates=[]
m = 0
while(i<21):
url = 'http://www.goal.com/en-gb/rumours/last/168?page='+str(i)+'&ICID=OP'
response = urllib2.urlopen(url)
html = response.read()
soup = BeautifulSoup(html)
i +=1
# Collect rumors posts
rumour_post_tags = soup.find_all("div", {"id":"rumours"})
for rumour_tags in rumour_post_tags:
content_tags = rumour_tags.find_all("div",{"class":"rumour-content"})
for rumour in content_tags:
items.append(count)
count +=1
heads.append(rumour.find("h3",{'class':'column'}).text)
bodys.append(rumour.find('p').text)
for sources in rumour.find_all('span',{'class':'column'}):
for source in sources:
if m % 2 == 0:
writers.append(source)
m += 1
else:
dates.append(source)
m += 1
return render_template('index.html',allitems=zip(items,heads,bodys,writers,dates))
index.html
<!DOCTYPE html>
<html>
<head>
<title>Goal's Transfer Talks</title>
</head>
<body>
<h2>Transfer Talks</h2>
{% for item,head,body,writer,date in allitems %}
<h3>{{ item }}. {{ head }}</h3>
<p>{{ body }}</p>
<footer>
<p>{{ writer }}</p>
<p>{{ date }}</p>
</footer><br>
{% endfor %}
</body>
</html>
当我尝试通过http://rahul3103.pythonanywhere.com/
打开我的网站时出现错误:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
错误日志:
2015-07-29 11:17:57,179 :Exception on / [GET]
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/rahul3103/mysite/flask_app.py", line 19, in index
response = urllib2.urlopen(url)
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden
WSGI配置文件:
# This file contains the WSGI configuration required to serve up your
# web application at http://<your-username>.pythonanywhere.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#
# The below has been auto-generated for your Flask project
import sys
# add your project directory to the sys.path
project_home = u'/home/rahul3103/mysite'
if project_home not in sys.path:
sys.path = [project_home] + sys.path
# import flask app but need to call it "application" for WSGI to work
from flask_app import app as application