Zombie SharedDataMiddleware on Python Heroku

2024/11/15 11:14:15

I'm setting up a Flask app on Heroku. Everything is working fine until I added static files. I'm using this:

from werkzeug import SharedDataMiddleware
app = Flask(__name__)
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {'/static': os.path.join(os.path.dirname(__file__), 'static') })

The first time I deploy the app, the appropriate files in the ./static will be available at herokuapp.com/static. But after that initial deploy, the files never change on Heroku. If I change the last line to:

app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {'/assets': os.path.join(os.path.dirname(__file__), 'static') })

a new URL for the static files, herokuapp.com/assets, then I can see the updated files.

It seems like a mirror of the files gets stuck in the system. I've changed it four times and can access all of the URLs still.

Answer

SharedDataMiddleware defaults to sending Cache-Control and Expires HTTP headers, which means that your web browser may not even send a request to the server and just use the old files from cache. Try disabling the cache:

app.wsgi_app = SharedDataMiddleware(app.wsgi_app,{'/static': os.path.join(os.path.dirname(__file__), 'static')},cache=False)

Flask does the same with static files. To disable it there:

app.config['SEND_FILE_MAX_AGE_DEFAULT'] = None
https://en.xdnf.cn/q/71898.html

Related Q&A

Python: Urllib.urlopen nonnumeric port

for the following codetheurl = "https://%s:%[email protected]/nic/update?hostname=%s&myip=%s&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" % (username, password, hostname, theip)conn…

How to unittest the sequence of function calls made inside a python fuction?

I would like to unittest a fuction and assert if the sequence of function calls made inside the function workflow(). Something like,[1st called] fetch_yeargroup_ls()[2nd called] invoke_get_links().....…

OpenCV: Extract SURF Features from user-defined keypoints

I want to compute SURF Features from keypoints that I specify. I am using the Python wrapper of OpenCV. The following is the code I am trying to use, but I cannot find a working example anywhere.surf…

Realtime processing and callbacks with Python and C++

I need to write code to do some realtime processing that is fairly computationally complex. I would like to create some Python classes to manage all my scripting, and leave the intensive parts of the a…

How can I troubleshoot a segmentation fault when working with Python Ctypes and C++?

Lets say I have the following two function signatures in C++:BYTE* init( BYTE* Options, BYTE* Buffer )and:int next( BYTE* interface, BYTE* Buffer )The idea is that I first initialize an Interface class…

Undefined variable from import when using protocol buffers in PyDev

Ive got a PyDev project that uses protocol buffers. The protocol buffer files are located in a zip file generated by the protoc compiler. Everything works when I run the program, however PyDev reports …

Animating a network graph to show the progress of an algorithm

I would like to animate a network graph to show the progress of an algorithm. I am using NetworkX for graph creation. From this SO answer, I came up with a solution using clear_ouput from IPython.displ…

How to run grpc on ipv4 only

Im going to run a grpc server on IPv4 address like this: server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) protoc_pb2_grpc.add_ProtocServicer_to_server(StockProtocServicer(), server) ser…

Python/PyCharm mark unused import as used

I need to import a resource_rc.py file in my module. It is immediately marked by PyCharm as "unused". Is there a way to mark "unused" imports and also variables, etc. as used in Pyt…

Replacing every 2nd element in the list

I got a 2 dimensional list:[[5, 80, 2, 57, 5, 97], [2, 78, 2, 56, 6, 62], [5, 34, 3, 54, 6, 5, 2, 58, 5, 61, 5, 16]]In which I need to change every second element to 0, starting from first one. So it s…