Blank Page But No Error - Python Appengine

2019-08-21 12:29发布

I'm receiving intermittent blank pages on my appengine python website. Typically these come when a new process is started or when I flush the cache. There is a single white page served and once that has served everything is fine.

It's basically the same error as here:

http://groups.google.com/group/google-appengine/browse_thread/thread/c072383dc970e450

However, I have double and triple checked that I have the correct code on my python file (the following is copied and pasted):

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

Here is an example response in the logs that generated the blank page:

01-02 04:46AM 48.539 / 200 188ms 570cpu_ms 383api_cpu_ms 0kb

Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.19 Safari/534.13,gzip(gfe),gzip(gfe),gzip(gfe) 86.164.42.252 - tjcritchlow [02/Jan/2011:04:46:48 -0800] "GET / HTTP/1.1" 200 124 - "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.19 Safari/534.13,gzip(gfe),gzip(gfe),gzip(gfe)" "www.7bks.com" ms=188 cpu_ms=570 api_cpu_ms=383 cpm_usd=0.016028 I 01-02 04:46AM 48.724 Saved; key: appstats:008500, part: 82 bytes, full: 92081 bytes, overhead: 0.001 + 0.005; link: http://www.7bks.com/stats/details?time=1293972408543

Any suggestions welcome on how I might debug further or solve this issue.

I have a couple of different python files, here's the handlers from my app.yaml. But I've checked all of them to ensure they all have the correct if name code at the bottom.

handlers:

- url: /admin/.*
  script: admin.py
  login: admin

- url: /googleanalytics/
  script: googleanalytics.py
  login: admin

- url: /cleanupsessions/
  script: cleanupsessions.py
  login: admin

- url: /robots.txt
  static_files: robots.txt
  upload: robots.txt

- url: /favicon.ico
  static_files: images/favicon.ico
  upload: images/favicon.ico

- url: /images
  static_dir: images

- url: /css
  static_dir: css

- url: /jquery
  static_dir: jquery

- url: /.*
  script: 7books.py

error_handlers:
  - file: customerror.html

Could the issue be with one of the libraries I'm importing? Should I check all of them to ensure they all have the name code?

3条回答
家丑人穷心不美
2楼-- · 2019-08-21 13:08

Regarding the blank page issue, debugging that might be a bit involved unless you can narrow down the problem to a particular piece of your code or the GAE stack.

Appstats is a tool for GAE that hooks into each web request (as WSGI middleware) and records performance, debugging, and some other information from requests, aggregating them in an administrative interface which you can access through your GAE admin site. It's a nice way of seeing tracebacks for errors, and monitoring your site for errors (which show up as yellow boxed "E" line items in the request listing once you've installed appstats).

First, you should set up Appstats by following the directions at:

http://code.google.com/appengine/docs/python/tools/appstats.html

...which will tell you loads of useful information about every request, especially ones with errors, including a Python traceback containing what went wrong and where in the call stack, just like you're used to when debugging errors with your code locally using the Google App Engine Launcher or even just Python CLI or iPython.

Then, next time you see a blank page, hop over to your admin page or to appstats, log in, and you'll have a traceback that will tell you where in your code something broke.

Most likely, this is just something returning prematurely or an unhandled edge case somewhere in your code, but it could just as easily be cosmic rays until you have appstats to look at your request logs and debug the error.

Once you've installed Appstats and reproduced the problem, paste the traceback above, (remember to remove any user information such as passwords that may be in the traceback), and I'll revise this response to match.

查看更多
小情绪 Triste *
3楼-- · 2019-08-21 13:22

Make sure your python indentation is consistent. For instance, either use tabs or 4 spaces or 2 spaces... don't mix them within the same function. This solved it for me! Which is annoying since a tab and 4 spaces look exactly the same to a human.

查看更多
男人必须洒脱
4楼-- · 2019-08-21 13:28

i just resolved this after lots of frustration.

i had renamed my script handler to 'site.py', renaming it back to 'main.py' resolved everything.

My best guess is that the stock python 'site' module was dominant on the classpath over my site.py. if someone knows more, please leave a comment here.

查看更多
登录 后发表回答