6

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.

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?

The file structure of my code is as follows:

  • Project
    • 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.

Any help would be greatly appreciated!

Thanks!

user2618340
  • 71
  • 1
  • 4
  • 1
    Hi. Make sure that you are calling dev_appserver.py command in the folder that contain the app.yaml file. In other case, please add more info about where you are executing this command. – Nico Apr 23 '16 at 02:24
  • 6
    Have you tried `dev_appserver.py app.yaml` from within helloworld folder? – Shark May 01 '16 at 20:39

6 Answers6

11

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

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

Keerthi Kumar P
  • 1,554
  • 9
  • 14
  • 1
    Yep, editing the registry fixed it for me. I needed to do the same thing on another machine, so I wrote these [step-by-step instructions](https://gist.github.com/bryik/1f507969f5239625628d6b63f04eae60). – bryik Jul 17 '17 at 02:35
  • Thanks! This fixed! – tmoore Sep 06 '17 at 12:24
6

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

Arush Salil
  • 163
  • 2
  • 10
3

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

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

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 :

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.
Nate Anderson
  • 18,334
  • 18
  • 100
  • 135
  • 1
    I can verify that I have the same issue. Also thought I only have one python, but I don't. Thanks for the hint @the-red-pea – Mathias Apr 26 '17 at 02:37
  • Thanks @Mathias , if this answer helped you, consider upvoting it so that others may consider it helpful – Nate Anderson Apr 26 '17 at 02:44
  • 1
    Since it might be helpful to others, I worked around this issue by writing a gulp wrapper around launching the `dev_appserver.py` specifically, like mentioned above. https://gist.github.com/MathiasPaumgarten/a8f5b320ccdb64b66b662b26a175f87c – Mathias May 15 '17 at 17:29
  • Cheers, @Mathias , I agree. [Here is mine (it's a bash script)](https://gist.github.com/theredpea/821d2138d1fffcbbe0f59f22865e9ac2) I like gulp lately, will probably switch to yours! – Nate Anderson May 15 '17 at 17:55
2

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:

...\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:

parser.add_argument(
  '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!

0

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

niranjanbajgai
  • 295
  • 1
  • 3
  • 8
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.

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

> 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
yasirfarooqui
  • 193
  • 1
  • 9