Rahul Shrivastava
Rahul Shrivastava

Reputation: 1411

PythonAnywhere trying to upload my website

I am trying to upload my web-app on PythonAnywhere, but I am not able to do that.I have tried many ways and also searched on google but I am unable to solve it. Please tell me what I am lacking in or what more information should I add here. I have also added the Error Log from PythonAnywhere. Please someone explain me the error also if possible as what I am doing wrong.

my file structure

|-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>

I am getting an error when I am trying to open my website through http://rahul3103.pythonanywhere.com/ which is:

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.

Error Log:

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 Configuration file:

# 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

Upvotes: 2

Views: 1444

Answers (1)

Glenn
Glenn

Reputation: 5786

It's because you have a free account and PythonAnywhere only allows access to the internet for a whitelist of sites.

Upvotes: 1

Related Questions