Error 302 running cron and login:admin in app.yaml in google app engine

897 views
Skip to first unread message

Pedro Perez Garcia

unread,
Oct 29, 2018, 1:51:32 PM10/29/18
to Google App Engine

I added login: Admin to app.yaml like documentation (https://cloud.google.com/appengine/docs/standard/python/config/appref#example)  is described, but I still have a 302 erro when runing a task with cron in google app engine.

I have this app.yaml

runtime: python27 
api_version: 1 
threadsafe: true

handlers:
- url: /.*   
  script: main.app   
  login: admin


And this cron.yaml

cron:
- description: "Dashboard"
  url: /processdate?from=2016-03-01&until=2016-03-31
  schedule: every day 23:46
  timezone: Europe/Madrid


I obtain this error

0.1.0.1 - - [26/Oct/2018:00:49:40 +0200] "GET /processdate?from=2016-03-01&until=2016-03-31 HTTP/1.1" 302 355 - "AppEngine-Google; (+http://code.google.com/appengine)" "p201309.appspot.com" ms=74 cpu_ms=12 cpm_usd=3.9674e-8 loading_request=0 instance=00c61b117c78f767097d6896daa1f8967a815c14a94d54578ac19efa9d50a5077d5a app_engine_release=1.9.65 trace_id=3c92edad090b5a57d249bd92be246e58

 httpRequest: {
  status:  302   
 }
 insertId:  "5bd248840005a3aae7fa2111"  
 labels: {
  clone_id:  "00c61b117c78f767097d6896daa1f8967a815c14a94d54578ac19efa9d50a5077d5a"   
 }
 logName:  "projects/p201309/logs/appengine.googleapis.com%2Frequest_log"  
 operation: {
  first:  true   
  id:  "5bd2488400ff047fe69ec5d94d0001657e62692d70682d3230313330390001323031383130323674303033383339000100"   
  last:  true   
 }
 protoPayload: {
  appEngineRelease:  "1.9.65"   
  appId:  "e~bi-ph-201309"   
  cost:  3.9674e-8   
  endTime:  "2018-10-25T22:49:40.369327Z"   
  finished:  true   
  first:  true   
  host:  "p201309.appspot.com"   
  httpVersion:  "HTTP/1.1"   
  instanceId:  "00c61b117c78f767097d6896daa1f8967a815c14a94d54578ac19efa9d50a5077d5a"   
  instanceIndex:  -1   
  ip:  "0.1.0.1"   
  latency:  "0.074441s"   
  megaCycles:  "12"   
  method:  "GET"   
  requestId:  "5bd2488400ff047fe69ec5d94d0001657e62692d70682d3230313330390001323031383130323674303033383339000100"   
  resource:  "/processdate?from=2016-03-01&until=2016-03-31"   
  responseSize:  "355"   
  startTime:  "2018-10-25T22:49:40.294886Z"   
  status:  302   
  taskName:  "25ed634cde05b07d9a7906f2161d2b16"   
  taskQueueName:  "__cron"   
  traceId:  "3c92edad090b5a57d249bd92be246e58"   
  traceSampled:  true   
  urlMapEntry:  "main.app"   
  userAgent:  "AppEngine-Google; (+http://code.google.com/appengine)"   
  versionId:  "20181026t003839"   
 }
 receiveTimestamp:  "2018-10-25T22:49:40.376251430Z"  
 resource: {
  labels: {
   module_id:  "default"    
   project_id:  "bi-ph-201309"    
   version_id:  "20181026t003839"    
   zone:  "eu2"    
  }
  type:  "gae_app"   
 }
 timestamp:  "2018-10-25T22:49:40.294886Z"  
 trace:  "projects/bi-ph-201309/traces/3c92edad090b5a57d249bd92be246e58"  
 traceSampled:  true  
}



I added login: Admin to app.yaml like documentation is described, but I still have a 302 erro when runing a task with cron in google app engine.

I have this app.yaml

--------------
runtime: python27 
api_version: 1 
threadsafe: true

handlers:
- url: /.*   
  script: main.app   
  login: admin
--------------

And this cron.yaml

--------------
cron:
- description: "Dashboard"
  url: /processdate?from=2016-03-01&until=2016-03-31
  schedule: every day 23:46
  timezone: Europe/Madrid
--------------

I obtain this error

--------------
0.1.0.1 - - [26/Oct/2018:00:49:40 +0200] "GET /processdate?from=2016-03-01&until=2016-03-31 HTTP/1.1" 302 355 - "AppEngine-Google; (+http://code.google.com/appengine)" "p201309.appspot.com" ms=74 cpu_ms=12 cpm_usd=3.9674e-8 loading_request=0 instance=00c61b117c78f767097d6896daa1f8967a815c14a94d54578ac19efa9d50a5077d5a app_engine_release=1.9.65 trace_id=3c92edad090b5a57d249bd92be246e58

 httpRequest: {
  status:  302   
 }
 insertId:  "5bd248840005a3aae7fa2111"  
 labels: {
  clone_id:  "00c61b117c78f767097d6896daa1f8967a815c14a94d54578ac19efa9d50a5077d5a"   
 }
 logName:  "projects/p201309/logs/appengine.googleapis.com%2Frequest_log"  
 operation: {
  first:  true   
  id:  "5bd2488400ff047fe69ec5d94d0001657e62692d70682d3230313330390001323031383130323674303033383339000100"   
  last:  true   
 }
 protoPayload: {
  appEngineRelease:  "1.9.65"   
  appId:  "e~bi-ph-201309"   
  cost:  3.9674e-8   
  endTime:  "2018-10-25T22:49:40.369327Z"   
  finished:  true   
  first:  true   
  host:  "p201309.appspot.com"   
  httpVersion:  "HTTP/1.1"   
  instanceId:  "00c61b117c78f767097d6896daa1f8967a815c14a94d54578ac19efa9d50a5077d5a"   
  instanceIndex:  -1   
  ip:  "0.1.0.1"   
  latency:  "0.074441s"   
  megaCycles:  "12"   
  method:  "GET"   
  requestId:  "5bd2488400ff047fe69ec5d94d0001657e62692d70682d3230313330390001323031383130323674303033383339000100"   
  resource:  "/processdate?from=2016-03-01&until=2016-03-31"   
  responseSize:  "355"   
  startTime:  "2018-10-25T22:49:40.294886Z"   
  status:  302   
  taskName:  "25ed634cde05b07d9a7906f2161d2b16"   
  taskQueueName:  "__cron"   
  traceId:  "3c92edad090b5a57d249bd92be246e58"   
  traceSampled:  true   
  urlMapEntry:  "main.app"   
  userAgent:  "AppEngine-Google; (+http://code.google.com/appengine)"   
  versionId:  "20181026t003839"   
 }
 receiveTimestamp:  "2018-10-25T22:49:40.376251430Z"  
 resource: {
  labels: {
   module_id:  "default"    
   project_id:  "bi-ph-201309"    
   version_id:  "20181026t003839"    
   zone:  "eu2"    
  }
  type:  "gae_app"   
 }
 timestamp:  "2018-10-25T22:49:40.294886Z"  
 trace:  "projects/bi-ph-201309/traces/3c92edad090b5a57d249bd92be246e58"  
 traceSampled:  true  
}
--------------


Any idea about what could be the problem or how to solve it?

I don't have any problem runing this script in my local machine.

George (Cloud Platform Support)

unread,
Oct 29, 2018, 3:20:17 PM10/29/18
to Google App Engine
Hello Pedro, 

You have employed a URL that differs somewhat of what is expected in the cron.yaml configuration file: url: /processdate?from=2016-03-01&until=2016-03-31. This URL indicates a time interval, when the URL in your app is expected instead, to which you want the Cron service to send job requests. Have a look at the "Scheduling Jobs with cron.yaml" online document for more detail. 

Pedro Perez Garcia

unread,
Oct 29, 2018, 5:45:18 PM10/29/18
to google-a...@googlegroups.com
(Note: I work on standard enviroment).

I tested something more simple and I had the same error:

-----------  app.yaml
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /hellocron
  script: main.app
  login: admin

----------- cron.yaml
cron:
- description: "hellocron"
  url: /hellocron
  schedule: every day 23:46
  timezone: Europe/Madrid

------------  This is the result

0.1.0.1 - - [29/Oct/2018:18:22:21 +0100] "GET /hellocron HTTP/1.1" 302 267 - "AppEngine-Google; (+http://code.google.com/appengine)" "myappname.appspot.com" ms=7 cpu_ms=8 cpm_usd=2.9839e-8 loading_request=0 instance=00c61b117c0e3de0cc2930f468114e719ef64c3a7928241d0646746341aa2f7386732a app_engine_release=1.9.65 trace_id=b6e54d8d997807741af6254abc0dfbf8
Mostrar todo | Ocultar todo {
 httpRequest: {
  status:  302   
 }
 insertId:  "5bd741cd000e2051b7f2899c"  
 labels: {
  clone_id:  "00c61b117c0e3de0cc2930f468114e719ef64c3a7928241d0646746341aa2f7386732a"   
 }
 logName:  "projects/myappname/logs/appengine.googleapis.com%2Frequest_log"  
 operation: {
  first:  true   
  id:  "5bd741cd00ff0e028bbe1c89380001657e62692d70682d3230313330390001323031383130323974313831333334000100"   
  last:  true   
 }
 protoPayload: {
  appEngineRelease:  "1.9.65"   
  appId:  "e~myappname"   
  cost:  2.9839e-8   
  endTime:  "2018-10-29T17:22:21.925588Z"   
  finished:  true   
  first:  true   
  host:  "myappname.appspot.com"   
  httpVersion:  "HTTP/1.1"   
  instanceId:  "00c61b117c0e3de0cc2930f468114e719ef64c3a7928241d0646746341aa2f7386732a"   
  instanceIndex:  -1   
  ip:  "0.1.0.1"   
  latency:  "0.007433s"   
  megaCycles:  "8"   
  method:  "GET"   
  requestId:  "5bd741cd00ff0e028bbe1c89380001657e62692d70682d3230313330390001323031383130323974313831333334000100"   
  resource:  "/hellocron"   
  responseSize:  "267"   
  startTime:  "2018-10-29T17:22:21.918155Z"   
  status:  302   
  taskName:  "b0467e8a57f53a8ee2b827ca35db275f"   
  taskQueueName:  "__cron"   
  traceId:  "b6e54d8d997807741af6254abc0dfbf8"   
  traceSampled:  true   
  urlMapEntry:  "main.app"   
  userAgent:  "AppEngine-Google; (+http://code.google.com/appengine)"   
  versionId:  "20181029t181334"   
 }
 receiveTimestamp:  "2018-10-29T17:22:21.927708910Z"  
 resource: {
  labels: {
   module_id:  "default"    
   project_id:  "myappname"    
   version_id:  "20181029t181334"    
   zone:  "eu2"    
  }
  type:  "gae_app"   
 }
 timestamp:  "2018-10-29T17:22:21.918155Z"  
 trace:  "projects/myappname/traces/b6e54d8d997807741af6254abc0dfbf8"  
 traceSampled:  true  
}




El lun., 29 oct. 2018 a las 20:20, 'George (Cloud Platform Support)' via Google App Engine (<google-a...@googlegroups.com>) escribió:
Hello Pedro, 

You have employed a URL that differs somewhat of what is expected in the cron.yaml configuration file: url: /processdate?from=2016-03-01&until=2016-03-31. This URL indicates a time interval, when the URL in your app is expected instead, to which you want the Cron service to send job requests. Have a look at the "Scheduling Jobs with cron.yaml" online document for more detail. 

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/b9558ba1-a3ed-434b-8cc9-fb835e046ad6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

George (Cloud Platform Support)

unread,
Oct 30, 2018, 10:53:59 AM10/30/18
to Google App Engine
Your cron correctly calls /hellocron. The 302 error is returned from the call, so your handler needs attention, not cron. Error code 302 means "Found: Resource temporarily located elsewhere according to the Location header". You may read more detail on the "HTTP Status and Error Codes for JSON" page

Pedro Perez Garcia

unread,
Oct 30, 2018, 3:29:06 PM10/30/18
to google-a...@googlegroups.com

Hi,

I'm using this handler in app.yaml

--------------  app.yaml
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /hellocron
  script: main.app
  login: admin
------------

When I run it on google chrome with this url  (https://myappname.appspot.com/hellocron) it's working, it returns what is expected

It's returning 302 when I run it by cron.

I tested to deploy the same application to another project and the error is the same.

Thanks in advance!



El mar., 30 oct. 2018 a las 15:54, 'George (Cloud Platform Support)' via Google App Engine (<google-a...@googlegroups.com>) escribió:
Your cron correctly calls /hellocron. The 302 error is returned from the call, so your handler needs attention, not cron. Error code 302 means "Found: Resource temporarily located elsewhere according to the Location header". You may read more detail on the "HTTP Status and Error Codes for JSON" page

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

Sam (Google Cloud Support)

unread,
Oct 31, 2018, 11:59:27 AM10/31/18
to Google App Engine
Hi,

Notice that the URL you run in chrome  (https://myappname.appspot.com/hellocron) is SSL protected. It could be that the URL which cron is using is 'http' which outputs the 302. So the request to 'http' is being redirected 'https'.

As you have set 'login: admin' for your cron job handler in the app.yaml to secure this particular URL from unauthorized third parities, you will have to disable the HTTPS requirements specifically for the cron URL in your application's SSL configuration [1][2]. This article also discusses a similar issue from a GAE Java app perspective [3].

Pedro Perez Garcia

unread,
Nov 1, 2018, 8:21:15 AM11/1/18
to google-a...@googlegroups.com

Hi,

I've tested with this app.yaml

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /hellocron
  script: main.app
  login: admin
  secure: always


But nothing changed. Could you give me more details about how to test what you told me?

Thanks


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.

Mohammad I (Cloud Platform Support)

unread,
Nov 1, 2018, 8:22:01 PM11/1/18
to Google App Engine

Hello Pedo,


When you create a handler for cron job, it should execute any tasks that you want to be scheduled. To indicate success, the handler should return with HTTP status code between 200 and 299. You can find about this in the third point of the “Creating a cron job“ section of this document.  When App Engine gets the HTTP GET request it converts it to a HTTPS request for your application. Therefore you can see the 302 redirect status code in the log. When your request is redirected the HTTP status code will be set to the value of the redirect_http_response_code parameter returned from your application. In your case the parameter may be not present which leads the 302 to be returned which is described here. As a result, App Engine is considering the cron job as failed.


I would advise you to go through your code and make proper adjustments.


In addition, I have noticed your project_id, module_id, version_id etc. in this Google Group thread. I would advise you to take caution before sharing any personal project specific information like these in any public forums as they can be used to harm your application.


Pedro Perez Garcia

unread,
Nov 18, 2018, 5:07:25 AM11/18/18
to Google App Engine
Reply all
Reply to author
Forward
0 new messages