首先让我说我认为这实际上行不通,但是,在我放弃引入这个库的努力之前,我想确定一下。所以我使用 easy_install 添加了一个我在 Github 上找到的 API 库。我希望在我的 appengine 应用程序中使用它。我编写了一个简单的测试处理程序,它将创建模块主类的一个实例并打印一个请求。我的 dev_appserver 将启动,但不会加载 MainPage。 任何建议表示赞赏!
错误是:
ERROR 2013-06-21 04:24:00,450 wsgi.py:219]
Traceback (most recent call last):
File "/home/devin/google_appengine/google/appengine/runtime/wsgi.py", line 196, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/devin/google_appengine/google/appengine/runtime/wsgi.py", line 255, in _LoadHandler
handler = __import__(path[0])
File "/home/devin/Projects/appengine/hackTheMidwest/perfectpet4me.py", line 4, in <module>
import petfinder
ImportError: No module named petfinder
INFO 2013-06-21 04:24:00,455 server.py:593] default: "GET / HTTP/1.1" 500 -
这是我的主文件的代码:
import os
import urllib
import petfinder # THE INSTALLED LIBRARY
from google.appengine.api import users
import jinja2
import webapp2
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'])
class MainPage(webapp2.RequestHandler):
def get(self):
template = JINJA_ENVIRONMENT.get_template('templates/index.html')
self.response.write(template.render())
class TestPage(webapp2.RequestHandler):
def get(self):
# Instantiate the client with your credentials.
api = petfinder.PetFinderClient(api_key='#####', api_secret='#####')
pet = api.pet_getrandom()
self.response.write(pet['name'])
application = webapp2.WSGIApplication([
('/', MainPage),
('/test', TestPage),
], debug=True)
还有我的 app.yaml:
application: ASDFASDFASDF
version: 1
runtime: python27
api_version: 1
threadsafe: true
- url: /.*
script: perfectpet4me.application
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest