Python 2.5 Google App Engine [关闭]

Posted

技术标签:

【中文标题】Python 2.5 Google App Engine [关闭]【英文标题】:Python 2.5 Google App Engine [closed] 【发布时间】:2012-04-14 15:05:00 【问题描述】:

我正在尝试从 python 获取此工作代码以在 Google App Engine Launcher 中工作,但我的代码可能有问题。它是 Python 中的工作代码,但由于某种原因,GAE 启动器无法正常工作。 这是代码:

fname = raw_input('Enter your first name: ')
lname = raw_input('Enter your last name: ')
day = int(raw_input("Enter your birth day: "))
month = int(raw_input("Enter your birth month: "))
year = int(raw_input("Enter your full birth year. (eg. 1990): "))

fullname = fname+spc+lname
byear = month+day+year

yrstr=str(byear)
accum1=0
a=yrstr
for b in a:
    x=int(b)
accum1 += x

bnumber=0
accum2=str(accum1)
a=accum2
for b in a:
    x=int(b)
    bnumber +=x


print "Hello", fullname, "I hope you're having a great day!"
print "Your birth number is: ", bnumber
print "According to the birth test, you are:"

if bnumber == 1:
  print """
#1 - THE ORIGINATOR
1's are originals.
Coming up with new ideas and executing them is natural.
Having things their own way is another trait that gets
them as being stubborn and arrogant."""

elif bnumber == 2:
    print """
#2 - THE PEACEMAKER
2's are the born diplomats.
They are aware of others' needs and moods and often think
of others before themselves.
Naturally analytical and very intuitive they don't like to be alone."""

elif bnumber == 3:
    print """
#3 - THE LIFE OF THE PARTY
3's are idealists.
They are very creative, social, charming, romantic, and easygoing.
They start many things, but don't always see them through."""

elif bnumber == 4:
    print """
#4 - THE CONSERVATIVE
4's are sensible and traditional.
They like order and routine.
They only act when they fully understand what they are expected to do.
They like getting their hands dirty and working hard.
They are attracted to the outdoors and feel an affinity with nature."""

elif bnumber == 5:
    print """
#5 - THE NONCONFORMIST
5's are the explorers.
Their natural curiosity, risk taking, and enthusiasm
often lands them in hot water.
They need diversity, and don't like to be stuck in a rut.
The whole world is their school and they see
a learning possibility in every situation."""

elif bnumber == 6:
    print """
#6 - THE ROMANTIC
6's are idealistic and need to feel useful to be happy.
A strong family connection is important to them.
Their actions influence their decisions.
They have a strong urge to take care of others and to help.
They are very loyal and make great teachers.
They like art or music.
They make loyal friends who take the friendship seriously."""

elif bnumber == 7:
    print """
#7 - THE INTELLECTUAL
7's are the searchers.
Always probing for hidden information, they find it difficult
to accept things at face value.
Emotions don't sway their decisions.
Questioning everything in life, they don't like to be questioned themselves.
They're never off to a fast start,
and their motto is slow and steady wins the race."""

elif bnumber == 8:
    print """
 #8 - THE BIG SHOT
8's are the problem solvers.
They are professional, blunt and to the point,
have good judgment and are decisive.
They have grand plans and like to live the good life.
They take charge of people."""

elif bnumber == 9:
    print """
#9 - THE PERFORMER
9's are natural entertainers.
They are very caring and generous, giving away their last dollar to help.
With their charm, they have no problem making friends
and nobody is a stranger to them.
They have so many different personalities that people around them
have a hard time understanding them."""

print
junk = raw_input("Press Enter to exit ")

来自 GAE 启动器的日志文件是这样写的:

2012-03-31 18:49:04 Running command: "['C:\\Python25\\python.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--admin_console_server=', '--port=8080', u'C:\\Users\\PCX2\\Desktop\\testengine']"
WARNING  2012-04-01 01:49:06,825 urlfetch_stub.py:111] No ssl package found. urlfetch will not be able to validate SSL certificates.
WARNING  2012-04-01 01:49:06,923 rdbms_mysqldb.py:74] The rdbms API is not available because the MySQLdb library could not be loaded.
WARNING  2012-04-01 01:49:07,144 dev_appserver.py:3375] Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO     2012-04-01 01:49:07,164 dev_appserver_multiprocess.py:650] Running application dev~birthtest on port 8080: http://localhost:8080
INFO     2012-04-01 01:49:07,164 dev_appserver_multiprocess.py:652] Admin console is available at: http://localhost:8080/_ah/admin

当我在启动器上点击浏览时,这也是我得到的错误:

<type 'exceptions.ImportError'> Python 2.5.1: C:\Python25\python.exe
Sun Apr 01 01:54:51 2012
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

 C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py in _HandleRequest(self=<google.appengine.tools.dev_appserver.DevAppServerRequestHandler instance at 0x03CC8210>)
 2753         outfile = cStringIO.StringIO()
 2754         try:
 2755           self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
 2756         finally:
 2757           self.module_manager.UpdateModuleFileModificationTimes()
self = <google.appengine.tools.dev_appserver.DevAppServerRequestHandler instance at 0x03CC8210>, self._Dispatch = <bound method DevAppServerRequestHandler._Dispat...vAppServerRequestHandler instance at 0x03CC8210>>, dispatcher = <google.appengine.tools.dev_appserver.MatcherDispatcher object at 0x03CCA650>, self.rfile = <socket._fileobject object at 0x03CC3EB0>, outfile = <cStringIO.StringO object at 0x03CCA0C0>, env_dict = 'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~birthtest', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'B6589FC6', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.3', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...
 C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py in _Dispatch(self=<google.appengine.tools.dev_appserver.DevAppServerRequestHandler instance at 0x03CC8210>, dispatcher=<google.appengine.tools.dev_appserver.MatcherDispatcher object at 0x03CCA650>, socket_infile=<socket._fileobject object at 0x03CC3EB0>, outfile=<cStringIO.StringO object at 0x03CCA0C0>, env_dict='APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~birthtest', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'B6589FC6', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.3', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...)
 2641           dispatcher.Dispatch(app_server_request,
 2642                               outfile,
 2643                               base_env_dict=env_dict)
 2644         finally:
 2645           request_file.close()
base_env_dict undefined, env_dict = 'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~birthtest', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'B6589FC6', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.3', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...
 C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py in Dispatch(self=<google.appengine.tools.dev_appserver.MatcherDispatcher object at 0x03CCA650>, request=<AppServerRequest relative_url: / path: BTGAE.py...mp', mode 'rb' at 0x02DF6F08> force_admin: False>, outfile=<cStringIO.StringO object at 0x03CCA0C0>, base_env_dict='APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~birthtest', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'B6589FC6', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.3', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...)
  680         forward_request = dispatcher.Dispatch(request,
  681                                               outfile,
  682                                               base_env_dict=base_env_dict)
  683 
  684         if forward_request:
base_env_dict = 'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~birthtest', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'B6589FC6', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.3', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...
 C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py in Dispatch(self=<google.appengine.tools.dev_appserver.CGIDispatcher object at 0x03CBDF70>, request=<AppServerRequest relative_url: / path: BTGAE.py...mp', mode 'rb' at 0x02DF6F08> force_admin: False>, outfile=<cStringIO.StringO object at 0x03CCA0C0>, base_env_dict='APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~birthtest', 'CURRENT_VERSION_ID': '1.1', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'B6589FC6', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.6.3', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'SERVER_PROTOCOL': 'HTTP/1.0', ...)
 1715                      memory_file,
 1716                      outfile,
 1717                      self._module_dict)
 1718     finally:
 1719       logging.root.level = before_level
self = <google.appengine.tools.dev_appserver.CGIDispatcher object at 0x03CBDF70>, self._module_dict = 'BTGAE': <module 'BTGAE' from 'C:\Users\PCX2\Desktop\testengine\BTGAE.py'>, '__builtin__': <module '__builtin__' (built-in)>, '__main__': <module 'BTGAE' from 'C:\Users\PCX2\Desktop\testengine\BTGAE.py'>, '_types': <module '_types' (built-in)>, 'bdb': <module 'bdb' from 'C:\Python25\lib\bdb.pyc'>, 'cStringIO': <module 'cStringIO' (built-in)>, 'cmd': <module 'cmd' from 'C:\Python25\lib\cmd.pyc'>, 'codecs': <module 'codecs' from 'C:\Python25\lib\codecs.pyc'>, 'email': <module 'email' from 'C:\Python25\lib\email\__init__.pyc'>, 'email.Charset': <email.LazyImporter object at 0x032480B0>, ...
 C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py in ExecuteCGI(config=<AppInfoExternal error_handlers=None b...one api_version=1 api_config=None >, root_path=r'C:\Users\PCX2\Desktop\testengine', handler_path='BTGAE.py', cgi_path=r'C:\Users\PCX2\Desktop\testengine\BTGAE.py', env='APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~birthtest', 'AUTH_DOMAIN': 'gmail.com', 'CONTENT_LENGTH': '', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'CURRENT_VERSION_ID': '1.1', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8', ..., infile=<cStringIO.StringO object at 0x03CCA4E0>, outfile=<cStringIO.StringO object at 0x03CCA0C0>, module_dict='BTGAE': <module 'BTGAE' from 'C:\Users\PCX2\Desktop\testengine\BTGAE.py'>, '__builtin__': <module '__builtin__' (built-in)>, '__main__': <module 'BTGAE' from 'C:\Users\PCX2\Desktop\testengine\BTGAE.py'>, '_types': <module '_types' (built-in)>, 'bdb': <module 'bdb' from 'C:\Python25\lib\bdb.pyc'>, 'cStringIO': <module 'cStringIO' (built-in)>, 'cmd': <module 'cmd' from 'C:\Python25\lib\cmd.pyc'>, 'codecs': <module 'codecs' from 'C:\Python25\lib\codecs.pyc'>, 'email': <module 'email' from 'C:\Python25\lib\email\__init__.pyc'>, 'email.Charset': <email.LazyImporter object at 0x032480B0>, ..., exec_script=<function ExecuteOrImportScript at 0x03CBFD70>, exec_py27_handler=<function ExecutePy27Handler at 0x03CBFDB0>)
 1619         reset_modules = exec_py27_handler(config, handler_path, cgi_path, hook)
 1620       else:
 1621         reset_modules = exec_script(config, handler_path, cgi_path, hook)
 1622     except SystemExit, e:
 1623       logging.debug('CGI exited with status: %s', e)
reset_modules = True, exec_script = <function ExecuteOrImportScript at 0x03CBFD70>, config = <AppInfoExternal error_handlers=None b...one api_version=1 api_config=None >, handler_path = 'BTGAE.py', cgi_path = r'C:\Users\PCX2\Desktop\testengine\BTGAE.py', hook = <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object at 0x03336270>
 C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py in ExecuteOrImportScript(config=<AppInfoExternal error_handlers=None b...one api_version=1 api_config=None >, handler_path='BTGAE.py', cgi_path=r'C:\Users\PCX2\Desktop\testengine\BTGAE.py', import_hook=<google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object at 0x03336270>)
 1307 
 1308     if module_code:
 1309       exec module_code in script_module.__dict__
 1310     else:
 1311       script_module.main()
module_code = <code object <module> at 03B4E458, file "C:\Users\PCX2\Desktop\testengine\BTGAE.py", line 7>, script_module = <module 'BTGAE' from 'C:\Users\PCX2\Desktop\testengine\BTGAE.py'>, script_module.__dict__ = '__builtins__': 'ArithmeticError': <type 'exceptions.ArithmeticError'>, 'AssertionError': <type 'exceptions.AssertionError'>, 'AttributeError': <type 'exceptions.AttributeError'>, 'BaseException': <type 'exceptions.BaseException'>, 'DeprecationWarning': <type 'exceptions.DeprecationWarning'>, 'EOFError': <type 'exceptions.EOFError'>, 'Ellipsis': Ellipsis, 'EnvironmentError': <type 'exceptions.EnvironmentError'>, 'Exception': <type 'exceptions.Exception'>, 'False': False, ..., '__doc__': None, '__file__': r'C:\Users\PCX2\Desktop\testengine\BTGAE.py', '__loader__': <google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook object at 0x03336270>, '__name__': 'BTGAE'
 C:\Users\PCX2\Desktop\testengine\BTGAE.py in ()
    5 
    6 
    7 from appconsole import myprint, printoutput
    8 
    9 def prog_gen(namn=""):
appconsole undefined, myprint undefined, printoutput undefined
<type 'exceptions.ImportError'>: No module named appconsole

【问题讨论】:

您是否收到错误消息?如果是这样,请将其添加到问题中。谢谢 这段代码是为在命令行中使用而设计的,与应用引擎提供的框架关系不大。请阅读可用的文档here 这段代码与 GAE 没有任何关系。它只是一个基本的 Python 控制台应用程序。上面提供的链接@jpm 是学习如何将 Python 与 Google App Engine 结合使用的最佳资源。 我也从使用 raw_input 得到 EOF 错误。我应该使用 Google App enging Interactive 控制台来让此代码在 GAE 上运行吗? 【参考方案1】:

这不是 App Engine 应用程序;启动器将无法将其作为一个整体运行。有关编写 App Engine 应用程序的教程,请参阅here。

【讨论】:

那么python编码是从哪里来的呢?因为我已经阅读了该教程,但我仍然对在哪个平台上编写此代码感到困惑? SDK控制台可能吗?但这不使用 raw_inputs,所以让这个程序与 GAE 一起工作有点困难。 @user1302078 App Engine 应用程序是用 Python 或 Java 编写的,但您正在尝试运行旨在在控制台上运行的应用程序。您不能简单地将其传递给 App Engine 并期望它工作 - 您必须编写一个 web 应用程序,并通过 HTTP 和表单接口接受输入。 那我要在 Python 编辑器中更改代码吗?我只是很困惑我是编程新手,您知道如何使该代码在 GAE 中工作吗?我只是对此感到迷茫。我应该使用 Django 吗?如果可以的话,我会很感激你的帮助? @JessRajah 从教程开始。一旦你了解了编写 webapp 的基础知识——具体来说,从用户那里获取输入,并将输出返回给他们——你就会明白如何编写一个 webapp 来做你想做的事情。我还推荐 Charles Severance 的“使用 Google App Engine”。 尼克 我很欣赏这本书的参考。我的 GAE 项目和上面的代码仍然有问题。我现在使用 Django 编写代码,我至少在正确的轨道上吗?

以上是关于Python 2.5 Google App Engine [关闭]的主要内容,如果未能解决你的问题,请参考以下文章

Python pytesseract - 找不到 eng.traineddata - oem 2

python Google App Engine交互式python shell

python Google App Engine交互式python shell

Google App Engine - 大查询 - Python 找不到库 google.cloud

python 将Google App Engine SDK添加到Python virtualenv

google-app-engine:google api python客户端hello world中的ImportError httplib2