GAE Python:dev_appserver.py:错误:参数太少


I am trying to run the basic helloworld code described here https://cloud.google.com/appengine/docs/python/. However, whenever I try the dev_appserver.py helloworld/ command, I get a usage error for the dev_appserver.py command.

我正在尝试运行此处描述的基本helloworld代码https://cloud.google.com/appengine/docs/python/。但是,每当我尝试使用dev_appserver.py helloworld /命令时,我都会收到dev_appserver.py命令的使用错误。

I have installed Python 2.7 and also have Python 2.7 Anaconda installed on my system. Could the Anaconda Python be the cause of the issue?

我安装了Python 2.7,并在我的系统上安装了Python 2.7 Anaconda。 Anaconda Python会成为问题的原因吗?

The file structure of my code is as follows:


  • Project
    • helloworld
      • app.yaml
      • 的app.yaml
      • helloworld.py
      • helloworld.py
    • helloworld app.yaml helloworld.py
    • README.md
    • README.md
  • 项目helloworld app.yaml helloworld.py README.md

I have tried executing the dev_appserver.py helloworld/ command from inside the 'Project' folder and the 'helloworld' folder. But I get the same error in both cases.

我尝试从'Project'文件夹和'helloworld'文件夹中执行dev_appserver.py helloworld /命令。但在这两种情况下我都得到同样的错误。

Any help would be greatly appreciated!




6 个解决方案



You just need to execute the dev_appserver.py with path to app.yaml in the command itself, as suggested in comments.




I think I have found the "real" problem behind this error.


Tried putting some print statements in the dev_appserver.py file and found that what ever argument we are giving is not being passed and hence the error. On googling came across this SO post which explains the problem. On doing that change the following command worked flawlessly :D


dev_appserver.py app.yaml

dev_appserver.py app.yaml

Quoting that SO answer for easier reference:


I think I solved this. For some reason there is a SECOND place in the registry (besides that shown by the file associations stored in HKEY_CLASSES_ROOT\Python.File\shell\open\command):

我想我解决了这个问题。由于某种原因,注册表中存在第二个位置(除了存储在HKEY_CLASSES_ROOT \ Python.File \ shell \ open \ command中的文件关联所示):

[HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command] @="\"C:\\Python25\\python.exe\" \"%1\" %*"

[HKEY_CLASSES_ROOT \ Applications \ python.exe \ shell \ open \ command] @ =“\”C:\\ Python25 \\ python.exe \“\”%1 \“%*”

This seems to be the controlling setting on my system. The registry setting above adds the "%*" to pass all arguments to python.exe (it was missing in my registry for some reason).




I think OP could've identified a potential issue when describing multiple Python installations.


If I don't specify which Python installation (I thought I only had one...), then, it fails:


C:\Python27>"C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py" "C:\users\jessmine\documents\ttbtamer\app.yaml"
usage: dev_appserver.py [-h] [-A APP_ID] [--host HOST] [--port PORT]
dev_appserver.py: error: too few arguments

But if I specify which Python to use by invoking Python first, @ C:\Python27\python.exe, then it works:

但是如果我首先通过调用Python来指定使用哪个Python,@ C:\ Python27 \ python.exe,那么它可以工作:

C:\Python27>"C:\Python27\python.exe" "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py" "C:\users\jessmine\documents\ttbtamer\app.yaml"
INFO     2016-11-18 10:09:14,299 devappserver2.py:769] Skipping SDK update check.

Anyway since I don't think I have other Python installations on my computer, then I may be misinterpreting the difference here. But for me, the fix is to explicitly invoke python.exe.


(And to be clear, I know about putting the Python.exe location into %PATH%, but I expected that if it wasn't there, that the error would've been something like "'dev_appserver.py' is not recognized as an internal or external command", rather than executing and printing a Python error....)




After changing the "associate a file type or protocol with a specific program" (example here) for *.py to explicitly use C:\Python27\python.exe , then I no longer needed to manually invoke C:\Python27\python.exe in my cmd; i.e. my first example worked correctly :

更改“将文件类型或协议与特定程序关联”(此处为示例)* .py以显式使用C:\ Python27 \ python.exe后,我不再需要手动调用C:\ Python27 \ python。 exe在我的cmd;即我的第一个例子正常工作:

C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin>dev_appserver.py "C:\users\jessmine\documents\ttbtamer\app.yaml"
INFO     2016-11-18 10:33:50,269 devappserver2.py:769] Skipping SDK update check.



I had the same problem. I even installed everything on a fresh machine and I was getting the same error again.


So I "debugged" dev_appserver.py and I discovered that the argument passed to it (i.e. 'app.yaml' or '.' or '\hello_world') was not passed down to the following code file:

所以我“调试”了dev_appserver.py,我发现传递给它的参数(即'app.yaml'或'。'或'\ hello_world')没有传递给下面的代码文件:


In this file the arguments were checked, producing the infamous error "too few arguments". Out of desperation for the time lost, I made a quick (and for sure ugly) patching.


I commented out at lines 302 and 303 the validation rule:


  'config_paths', metavar=arg_name, nargs='+', help=arg_help)

At line 758 I replaced:


options.config_paths, options.app_id)

with a static file name:


{'app.yaml'}, options.app_id)

At least now I am able again to start the server and develop my application. Now that I can work again, I will try to understand better how to correct the problem.


I'm not a Python nor a Google App Engine expert, so I hope someone will propose a better correction and a better explanation of the problem, because I cannot believe that Google can release such bugged code!

我不是Python也不是Google App Engine专家,所以我希望有人会提出更好的更正和更好的解释,因为我无法相信Google可以发布这样的错误代码!



I suggest cd into your helloworld folder and and run dev_appserver.py . don't forget the ending dot '.' sign. Hope it works




In my case I was able to resolve this issue by peforming following two actions: 1). added "python" in the start of the command 2). provided full path to the "dev_appserver.py" file.


So in Google docs you will find to execute the following:-

因此,在Google文档中,您会发现执行以下操作: -

> dev_appserver.py ./ --php_executable_path=/path/to/php-cgi

(note that I was trying to run the php example and on windows environment here...)


Instead running the following command worked:


> python "c:\<path to the directory containing the dev_appserver.py script>\dev_appserver.py" ./ --php_executable_path=/path/to/php-cgi