简体   繁体   中英

How to run two versions of an application using Google App Engine dev server with Python

I am using Ubuntu Server 13.10 and Python 2.7.

I would like to have two versions of my App Engine application: admin and the default version. I have defined these two versions. Currently, this is my app.yaml file:

application: application-id
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /css
  static_dir: css
- url: /js
  static_dir: js
- url: /
  script: python.MainPage.application
- url: /test.*
  script: gaeunit.application

libraries:
- name: webapp2
  version: latest
- name: jinja2
  version: latest


version: admin
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /css
  static_dir: css
- url: /js
  static_dir: js
- url: /.*
  script: python.MainPage.application
  login: admin
  auth_fail_action: unauthorized
- url: /test.*
  script: python.MainPage.appication

libraries:
- name: webapp2
  version: latest
- name: jinja2
  version: latest

When I deploy this code to App Engine, it works as expected. However, If I attempt to run it using dev_appserver.py found in the Google Cloud SDK, it fails with this traceback:

Traceback (most recent call last):
  File "/home/katie/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 82, in <module>
    _run_file(__file__, globals())
  File "/home/katie/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 78, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 902, in <module>
    main()
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 895, in main
    dev_server.start(options)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 672, in start
    options.yaml_files)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 556, in __init__
    module_configuration = ModuleConfiguration(yaml_path)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 82, in __init__
    self._yaml_path)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 272, in _parse_configuration
    return appinfo_includes.ParseAndReturnIncludePaths(f)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo_includes.py", line 63, in ParseAndReturnIncludePaths
    appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo.py", line 1826, in LoadSingleAppInfo
    listener.Parse(app_info)
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 226, in Parse
    self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
  File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 177, in _HandleEvents
    raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: Duplicate attribute 'version'.
  in "aerobic-arcade-514/default/app.yaml", line 24, column 10

You can launch two different dev app servers on two different ports, just override the default port with the --port= parameter, however you will need to have two app.yaml files separated, not using the same file as you did. When you run dev_appserver.py , use the config file as the final argument instead of the directory (which defaults to app.yaml ).

For example:

dev_appserver.py --port=8888 app_one.yaml
dev_appserver.py --port=9999 app_two.yaml

After your testing and before deploying, make sure you leave the definitive file with the name app.yaml ; otherwise, you won't be able to complete the process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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