Method Not Allowed | Flask

I am getting a Method Not Allowed error.

I don’t really know flask, but perhaps this will help?

The main answer says to also have 'GET' in methods along with 'POST'.

Are you by chance having read errors?

@Firepup650 No, I am not.

@NuclearPasta0 No luck :frowning:

Are you certain? This bug is having varying effects (For some users it’s causing a module not found error on Nodejs)

@Firepup650 100% sure. This is all a Flask error.

Just making sure, since this is a weird issue.

This isn’t a weird issue. It’s pretty common among beginners working with flask.

1 Like

I was referring to the currently ongoing issues with repls breaking their own filesystems.

repls are breaking their own filesystems?

This bug report and this page on

what route are you getting a method not allowed error on?

The index file route is where the error occurs (it’s the only route in the program).
Any ideas for a fix, @QwertyQwerty88?
The link is:

Try to run the app on Flaks’s default port (which is 5000)

Also, your index function is currently set up to handle both GET and POST requests, but I don’t see how you are distinguishing between them in your code?

1 Like

Oh, that’s probably it. Try to check the request method. If it’s a GET request you can simply render the template, if it’s a POST you can process the form.

@app.route('/', methods=["POST", "GET"])
def index():
    if request.method == "POST":
        form_url = request.form.get("url", default="")  # I used the default URL here
        answer = get_post(form_url)
        return render_template('index.html', answer=answer)
    else:  # If it's a GET request
        return render_template('index.html', answer="")
1 Like

@WindLother Great! It works! But, now when I submit a url in the form, it says NoneType object is not subscriptable. Why is this?

Somewhere in your code you are attempting to subscript (index or key) a variable which has a value of None .

@WindLother It’s line 15 in the get_post()function.

I think he did not found the element and the find method returned none (which is why get_post() must be returning none).
Try to check if topic is none. Create two checks (one for topic and another one for article).
Something like this:

def get_post(url=""):
    topic = create_soup(url)
    if topic is None:  # Make a check here
        return "Could not find the desired topic link"
    temp_soup = BeautifulSoup(requests.get(str(topic['href'])).content, 'html5lib')
    article = BeautifulSoup(str(temp_soup.find('div', attrs = {'id':'post_1'})), "html5lib").find('div', attrs = {'class':'post'})
    if article is None:  # And another one here
        return "Could not find the desired article"
    q = BeautifulSoup(str(article), 'html5lib').text
    return q