2

I have deployed the successfully running python flask app on pythonanywhere. Only the home page is showing but when I submit the form its throwing Internal Server Error.

What might be the case.Checking the console network ,the requests link I have used is not being visited and error comes ahead.

I have successfully installed requests and BeautifulSoup dependencies for the project in virtualenv.

Here is the code

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)

The GET methods is working well but for the POST methods its throwing an internal server Error. Home.html is the template file inside template directory. Same template is loaded in POST method but with some values when Form is submitted.

davidism
  • 121,510
  • 29
  • 395
  • 339
Tara Prasad Gurung
  • 3,422
  • 6
  • 38
  • 76

2 Answers2

2

URLs passed to requests must start with a scheme, such as http:// or https://. Your URL does not, so it raises a MissingScheme exception which explains exactly what the problem is.

MissingSchema: Invalid URL 'jobkhulyo.com': No schema supplied. Perhaps you meant http://jobkhulyo.com?

As it suggests, make the request to http://jobkhulyo.com.

When running the server locally in debug mode, Flask will show tracebacks for errors that occur. In production, it will show a 500 error but still log the traceback. Enable logging to see these errors, as described in Flask application traceback doesn't show up in server log.

Community
  • 1
  • 1
davidism
  • 121,510
  • 29
  • 395
  • 339
0

Actually the problem was pythonanywhere doesnot allow you to refer any external sites in your web app. I had few external links so the error came. You can add the external link that they have listed as whitelists which can be checked in their site.

Most importantly if its a free account you cant but It must be available on paid service

Tara Prasad Gurung
  • 3,422
  • 6
  • 38
  • 76