1

Previously in my python flask application I was able to use

photos.url("picture_name")

without any issue. But after updating few libraries in my project, Celery is throwing exception

RuntimeError: Application was not able to create a URL adapter for request independent URL generation. You might be able to fix this by setting the SERVER_NAME config variable.

I don't have SERVER_NAME in my config but I don't need. It was working previously without this config so I am expecting it should even work now. Does anyone have any idea what am I missing?

Waseem
  • 1,392
  • 5
  • 21
  • 30

1 Answers1

1

Celery is likely attempting to run a task outside of the request context, and so it does not know how to properly generate a URL. See the docs:

Setting a SERVER_NAME also by default enables URL generation without a request context but with an application context.

If you hard-code the server URL you can generate URLs with url_for outside of the request context.

jumbopap
  • 3,969
  • 5
  • 27
  • 47
  • I tried adding server name like SERVER_NAME = "localhost:5000" and run the application with this run_simple('0.0.0.0', 5000, application, use_reloader=True, use_debugger=True) but then none of my project assets were loading. – Waseem Jan 09 '16 at 18:47
  • How are they not loading? What asset path is the browser trying to load? I did this myself and the asset paths are still fine when I do something like a `url_for('static', filename='images/favicon.png')` – jumbopap Jan 09 '16 at 18:57
  • So I think the problem was that I was using SERVER_NAME = "127.0.0.1:5000" instead of SERVER_NAME = "localhost:5000" .With using 127.0.0.1, I was getting csrf_token missing on chrome but it was working fine in firefox. I found question about this problem here http://stackoverflow.com/questions/30134427/flask-wtf-csrf-validation-fails-when-app-moved-to-docker-production-environment – Waseem Jan 09 '16 at 20:02
  • Great! Feel free to check this answer if it helped you :) – jumbopap Jan 09 '16 at 20:06