简体   繁体   English

Django-Google App Engine Cron 300错误

[英]Django - Google App Engine Cron 300 Error

I am able to successfully run my "job" by visiting " https://keel-test.appspot.com/tasks/test/ ". 通过访问“ https://keel-test.appspot.com/tasks/test/ ”,我可以成功运行我的“工作”。 I tested the header using " http://www.webconfs.com/http-header-check.php " which returns a 200 response. 我使用“ http://www.webconfs.com/http-header-check.php ”测试了标头,该标头返回200响应。

I successfully pushed the following cron.yaml to Google App Engines: 我成功将以下cron.yaml推送到Google App Engines:

cron:
- description: "test"
  url: /tasks/test
  schedule: every 8 hours

I tried running the task via the GCP Console Task queues page. 我尝试通过GCP控制台任务队列页面运行任务。 However, the GCP console says that the CRON job returns a 300 error. 但是,GCP控制台说CRON作业返回300错误。 There are zero logs except that the page returns a 301 when run by CRON and 200 if the URL above is visited manually. 日志为零,但由CRON运行时页面返回301,而手动访问上述URL则返回200。

Here is the app.yaml: 这是app.yaml:

runtime: python
env: flex
entrypoint: gunicorn config.wsgi:application

runtime_config:
  python_version: 3

I had the same problem with Django 我对Django也有同样的问题

URLs (urls.py): ... url(r'^health_check/', health_check, name='health_check'), ... 网址(urls.py): ... url(r'^health_check/', health_check, name='health_check'), ...

My backend has the SSL Redirect enabled 我的后端启用了SSL重定向

SECURE_SSL_REDIRECT = True

Seeing that the app-engine crons do not follow redirects I had to disable the redirect for this one endpoint by adding the end point to the SECURE_REDIRECT_EXEMPT variable in settings.py 看到App Engine引擎不遵循重定向,我不得不通过将端点添加到settings.py的SECURE_REDIRECT_EXEMPT变量来禁用此端点的重定向

... SECURE_REDIRECT_EXEMPT = [r'^health_check/'] ...

Your cron job is hitting /tasks/test (without trailing slash). 您的Cron工作正在命中/tasks/test (不带斜杠)。 Your url handler either doesn't exist or has the trailing slash. 您的网址处理程序不存在或带有斜杠。

Try hitting https://keel-test.appspot.com/tasks/test (no slash). 尝试点击https://keel-test.appspot.com/tasks/test (无斜杠)。 It redirects. 重定向。 Thus, the 301 因此, 301

Your URL handler: 您的网址处理程序:

url(r'^tasks/test/$', investment_views.test, name='test_job')

insists there be a trailing slash. 坚持要在后面加上斜线。 Change that to: 更改为:

url(r'^tasks/test', investment_views.test, name='test_job')

And both (with and without slash, along with anything that starts with test (eg: testing123) will get to that handler. 并且两者(带斜线和不带斜线,以及以test开头的任何内容(例如:testing123)都将到达该处理程序。

or, use both handlers with end-of-url signaling $ sign, if you want both to work: 或者,如果您希望两者都起作用,请同时使用两个带有网址结尾信号$符号的处理程序:

url(r'^tasks/test$', investment_views.test, name='test_job')
url(r'^tasks/test/$', investment_views.test, name='test_job')

or, if you want your urls to always have the trailing slash, make sure your cron job urls obey that standard: 或者,如果您希望自己的网址始终带有斜杠,请确保您的Cron作业网址遵循以下标准:

cron:
- description: "test"
  url: /tasks/test/
  schedule: every 8 hours

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM