GAE Python 微服务不工作
GAE Python Microservice is not working
我有默认的 GAE 服务,尽管我想实现微服务。默认版本有两个版本,我只在其中一个版本中实现微服务,因为我需要在将其放入主版本之前对其进行测试。对于这个新的微服务,我创建了文件 my_module.py 和 my_module.yaml。当我 运行 代码“appcfg.py 更新 my_module.py”时,upload/update 完美地工作,如下面的日志所示:
10:28 AM Host: appengine.google.com
10:28 AM Application: application_name; module: my_module; version: one
10:28 AM Starting update of app: application_name, module: my_module, version: one
10:28 AM Getting current resource limits.
10:28 AM Scanning files on local disk.
10:28 AM Cloning 2 application files.
10:28 AM Compilation starting.
10:28 AM Compilation completed.
10:28 AM Starting deployment.
10:28 AM Checking if deployment succeeded.
10:28 AM Deployment successful.
10:28 AM Checking if updated app version is serving.
10:28 AM Completed update of app: application_name, module: my_module, version: one
然而,当我去 console.cloud.google.com 查看日志时,我经常看到一个错误:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
ImportError: No module named my_module
拜托,有人知道为什么会这样吗?
更新:我正在放置我的新微服务代码。
my_module.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import webapp2
class MainHandler(webapp2.RedirectHandler):
def get(self):
self.response.out.write('Hello!')
return
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
my_module.yaml
application: application_name
module: my_module
version: one
runtime: python27
api_version: 1
threadsafe: true
instance_class: B1
basic_scaling:
max_instances: 1
idle_timeout: 13s
skip_files:
- ^(./)?app.yaml
- ^(./)?app.yml
- ^(./)?index.yaml
- ^(./)?index.yml
- ^(./)?#.#
- ^(./)?.~
- ^(./)?..py[co]
- ^(./)?./RCS/.*
- ^(./)?..
- ^(./)?tests$
- ^(./)?node_modules/.*
- ^(./)?Gruntfile.js
- ^(./)?package.json
handlers:
- url: /.*
script: my_module.app
更新:解决方案
正如 Avinash Raj 在评论中建议的那样,我刚刚从 my_module.yaml 中删除了 - ^(./)?.. 并且它开始工作了。
我建议您从 skip_files
部分中删除 ^(./)?..
正则表达式 stmt,因为正则表达式中未转义的点不仅匹配点,而且匹配任何单个字符,这会导致跳过任何文件他们的名字中至少有两个字母。如果你真的是一个点,那么像 ^(./)?\.\.
一样转义它
我有默认的 GAE 服务,尽管我想实现微服务。默认版本有两个版本,我只在其中一个版本中实现微服务,因为我需要在将其放入主版本之前对其进行测试。对于这个新的微服务,我创建了文件 my_module.py 和 my_module.yaml。当我 运行 代码“appcfg.py 更新 my_module.py”时,upload/update 完美地工作,如下面的日志所示:
10:28 AM Host: appengine.google.com
10:28 AM Application: application_name; module: my_module; version: one
10:28 AM Starting update of app: application_name, module: my_module, version: one
10:28 AM Getting current resource limits.
10:28 AM Scanning files on local disk.
10:28 AM Cloning 2 application files.
10:28 AM Compilation starting.
10:28 AM Compilation completed.
10:28 AM Starting deployment.
10:28 AM Checking if deployment succeeded.
10:28 AM Deployment successful.
10:28 AM Checking if updated app version is serving.
10:28 AM Completed update of app: application_name, module: my_module, version: one
然而,当我去 console.cloud.google.com 查看日志时,我经常看到一个错误:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
ImportError: No module named my_module
拜托,有人知道为什么会这样吗?
更新:我正在放置我的新微服务代码。
my_module.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import webapp2
class MainHandler(webapp2.RedirectHandler):
def get(self):
self.response.out.write('Hello!')
return
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
my_module.yaml
application: application_name
module: my_module
version: one
runtime: python27
api_version: 1
threadsafe: true
instance_class: B1
basic_scaling:
max_instances: 1
idle_timeout: 13s
skip_files:
- ^(./)?app.yaml
- ^(./)?app.yml
- ^(./)?index.yaml
- ^(./)?index.yml
- ^(./)?#.#
- ^(./)?.~
- ^(./)?..py[co]
- ^(./)?./RCS/.*
- ^(./)?..
- ^(./)?tests$
- ^(./)?node_modules/.*
- ^(./)?Gruntfile.js
- ^(./)?package.json
handlers:
- url: /.*
script: my_module.app
更新:解决方案
正如 Avinash Raj 在评论中建议的那样,我刚刚从 my_module.yaml 中删除了 - ^(./)?.. 并且它开始工作了。
我建议您从 skip_files
部分中删除 ^(./)?..
正则表达式 stmt,因为正则表达式中未转义的点不仅匹配点,而且匹配任何单个字符,这会导致跳过任何文件他们的名字中至少有两个字母。如果你真的是一个点,那么像 ^(./)?\.\.