阅读背景:

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!

任何帮助将不胜感激!

Thanks!

谢谢!

6 个解决方案

#1


7  

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

您只需要在命令本身中执行带有app.yaml路径的dev_appserver.py,如注释中所示。

#2


5  

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

尝试将一些print语句放在dev_appserver.py文件中,发现我们给出的任何参数都没有被传递,因此错误。在谷歌搜索遇到这个SO帖子解释了这个问题。在进行此更改时,以下命令可以完美地运行:D

dev_appserver.py app.yaml

dev_appserver.py app.yaml

Quoting that SO answer for easier reference:

引用SO答案以便于参考:

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).

这似乎是我系统的控制设置。上面的注册表设置添加“%*”以将所有参数传递给python.exe(由于某种原因,它在我的注册表中丢失)。

#3


3  

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

我认为OP在描述多个Python安装时可能已经确定了一个潜在的问题。

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

如果我没有指定哪个Python安装(我以为我只有一个......),那么它会失败:

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]
...etc...
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.

无论如何,因为我认为我的计算机上没有其他Python安装,所以我可能会误解这里的差异。但对我来说,修复是显式调用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....)

(并且要清楚,我知道将Python.exe位置放入%PATH%,但我预计如果它不存在,那么错误就会像''dev_appserver.py'那样被识别为内部或外部命令“,而不是执行和打印Python错误....)

EDIT

编辑

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.

#4


1  

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')没有传递给下面的代码文件:

...\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py

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:

我在第302和303行注释了验证规则:

parser.add_argument(
  'config_paths', metavar=arg_name, nargs='+', help=arg_help)

At line 758 I replaced:

在第758行,我更换了:

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可以发布这样的错误代码!

#5


0  

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

我建议你进入你的helloworld文件夹并运行dev_appserver.py。不要忘记结束点'。'标志。希望它有效

#6


0  

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.

在我的情况下,我能够通过执行以下两个操作来解决此问题:1)。在命令的开头添加了“python”2)。提供了“dev_appserver.py”文件的完整路径。

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...)

(请注意,我试图在这里运行php示例并在Windows环境中...)

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

分享到: