Forums

Endpoint not being hit?

I have an endpoint function in my app.py:

UPLOAD_FOLDER = os.path.dirname(os.path.abspath(__file__))
OUTPUT_FOLDER = os.path.join(UPLOAD_FOLDER, "data/output/")

@app.route('/downloader', methods=['GET'])
def downloader():
    dt_string = datetime.now().strftime("%Y.%m.%d_%H.%M.%S")
    folder = OUTPUT_FOLDER + dt_string
    os.mkdir(folder)
    server.call(folder) #server side code that saves 1 or more files to the folder location
    zipf = zipfile.ZipFile(folder + '.zip', 'w', zipfile.ZIP_DEFLATED)
    for root, dirs, files in os.walk(folder):
        for file in files:
            zipf.write(os.path.join(folder, file), file)
    zipf.close()
    return send_file(folder + '.zip', mimetype='zip', as_attachment=True, attachment_filename=dt_string+'.zip')

that's supposed to be called from an html webpage:

<div class="container my-4">
    <a class="btn btn-danger btn-lg" role="button"
       href="/downloader">Button Name</a>

It all works fine on my local machine, but the endpoint is not being called on the deployed app (I have verified by looking at the access logs). I'm about 4 hours into my experience with pythonanywhere and am stumped. Any help would be appreciated.

What do you see client-side when you hit that endpoint?

The save file box does pop up, but it doesn't have the current date and time name (or any other random name I've tried giving the file). It's almost like a cached version of the function is running, but from what I've read there shouldn't be any caching.

Have you been reloading your code (using the button at the top of the "Web" page inside PythonAnywhere) after making code changes? If not, you'll still be running the version from the last reload.

About 1000 times :) My other edits are showing up, but this endpoint never gets hit (according to the access logs).

In addition to hitting the endpoint on button push, I've also tried just typing the endpoint into the browser. Same behavior: box pops up with old date, access logs do not show the GET request.

Could we try it?

Sure! http://erinkeith.pythonanywhere.com/ Choose the "Generate Rankings" page, choose one option from each of the 3 categories. You can click "Select" on the next two pages without choosing anything, then finally click the "Generate Ranking" button.

It did run once today, but now it's exhibiting the same behavior.

Maybe try https://help.pythonanywhere.com/pages/FlaskSendFileBytesIO/

I updated the code to use BytesIO. It hangs on my local machine, but when I pushed and reloaded (twice) to here, same behavior as before. It worked once this morning (the server resets as some point, cuz the logs were empty?), Now, after the one successful GET request, I'm just getting the same zipped file name, no GET on the endpoint, and my new code does not seem to be running.

What do you see in your logs?

So, I used the downloader the first time; works perfectly: files generated, zipped, and downloaded properly. I went through the same process again (with different data), nothing: same filename, same files in the zip. Access logs show the first GET, but none after. There's nothing in the error log.

134.197.0.23 - - [24/Jun/2021:17:49:25 +0000] "GET /pick_sources.html HTTP/1.1" 200 683 "http://erinkeith.pythonanywhere.com/program_source_importer" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.060 134.197.0.23 - - [24/Jun/2021:17:49:30 +0000] "POST /pick_sources.html HTTP/1.1" 302 243 "http://erinkeith.pythonanywhere.com/pick_sources.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.039 134.197.0.23 - - [24/Jun/2021:17:49:30 +0000] "GET /pick_columns.html HTTP/1.1" 200 5856 "http://erinkeith.pythonanywhere.com/pick_sources.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.021 134.197.0.23 - - [24/Jun/2021:17:49:42 +0000] "POST /pick_columns.html HTTP/1.1" 302 243 "http://erinkeith.pythonanywhere.com/pick_columns.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.036 134.197.0.23 - - [24/Jun/2021:17:49:43 +0000] "GET /pick_weights.html HTTP/1.1" 200 80802 "http://erinkeith.pythonanywhere.com/pick_columns.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.175 134.197.0.23 - - [24/Jun/2021:17:49:53 +0000] "POST /pick_weights.html HTTP/1.1" 302 253 "http://erinkeith.pythonanywhere.com/pick_weights.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.002 134.197.0.23 - - [24/Jun/2021:17:49:53 +0000] "GET /generate_rankings.html HTTP/1.1" 200 818 "http://erinkeith.pythonanywhere.com/pick_weights.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.008 134.197.0.23 - - [24/Jun/2021:17:49:56 +0000] "GET /downloader HTTP/1.1" 200 2305 "http://erinkeith.pythonanywhere.com/generate_rankings.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.921 134.197.0.23 - - [24/Jun/2021:17:50:38 +0000] "GET /pick_sources.html HTTP/1.1" 200 683 "http://erinkeith.pythonanywhere.com/generate_rankings.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.041 134.197.0.23 - - [24/Jun/2021:17:50:45 +0000] "POST /pick_sources.html HTTP/1.1" 302 243 "http://erinkeith.pythonanywhere.com/pick_sources.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.040 134.197.0.23 - - [24/Jun/2021:17:50:45 +0000] "GET /pick_columns.html HTTP/1.1" 200 6271 "http://erinkeith.pythonanywhere.com/pick_sources.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.093 134.197.0.23 - - [24/Jun/2021:17:50:55 +0000] "POST /pick_columns.html HTTP/1.1" 302 243 "http://erinkeith.pythonanywhere.com/pick_columns.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.050 134.197.0.23 - - [24/Jun/2021:17:50:55 +0000] "GET /pick_weights.html HTTP/1.1" 200 80607 "http://erinkeith.pythonanywhere.com/pick_columns.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.101 134.197.0.23 - - [24/Jun/2021:17:51:08 +0000] "POST /pick_weights.html HTTP/1.1" 302 253 "http://erinkeith.pythonanywhere.com/pick_weights.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.003 134.197.0.23 - - [24/Jun/2021:17:51:08 +0000] "GET /generate_rankings.html HTTP/1.1" 200 732 "http://erinkeith.pythonanywhere.com/pick_weights.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36" "134.197.0.23" response-time=0.001

That all appeared to me to be working. Use your browser developer tools to make sure that everything that you expect to be working in the client is actually working and that there are no errors being reported by your browser.

Fascinating! It was Google Chrome's disk caching. Guess I'll look into how to make this more user friendly, if possible. Thank you for your persistence in helping with this problem! I really appreciate it.