Python请求模块 - Google App Engine [英] Python Request Module - Google App Engine

查看:133
本文介绍了Python请求模块 - Google App Engine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导入我想在本地Google App Engine上查看的应用程序的请求模块。我收到了一个日志控制台错误,告诉我没有这样的模块存在。



我已经在命令行中安装了它(使用 pip ),甚至试图将它安装在我的项目目录中。当我这样做时,shell会告诉我:
$ b


需求已满足(使用--upgrade升级):/ Library / Python中的请求/2.7/site-packages。

App Engine告诉我模块不存在,并且shell说它已经安装它。

我不知道这是否是路径问题。如果是这样,我可以在我的Mac中找到的唯一与App Engine相关的应用程序是启动器?

解决方案

您需要放置请求模块,即请求文件夹的内容在您的项目目录中。只是为了清楚起见,你的应用程序目录应该看起来像

  /myapp/app.yaml 
/ myapp / main.py
/ myapp / requests / packages /
/myapp/requests/__init__.py
/myapp/requests/adapters.py
等...

然后在main.py中放入类似于

  import webapp2 
import requests
$ b $ class MainHandler(webapp2.RequestHandler):
def get(self):
g = requests.get 'http://www.google.com')
self.response.write(g.text)

app = webapp2.WSGIApplication([
('/', MainHandler)
],debug = True)


I'm trying to import the requests module for my app which I want to view locally on Google App Engine. I am getting a log console error telling me that "no such module exists".

I've installed it in the command line (using pip) and even tried to install it in my project directory. When I do that the shell tells me:

"Requirement already satisfied (use --upgrade to upgrade): requests in /Library/Python/2.7/site-packages".

App Engine is telling me that the module doesn't exist and the shell says it's already installed it.

I don't know if this is a path problem. If so, the only App Engine related application I can find in my mac is the launcher?

解决方案

You need to put the requests module i.e. the contents of the requests folder within your project directory. Just for the sake of clarity, your app directory should look like

/myapp/app.yaml
/myapp/main.py
/myapp/requests/packages/
/myapp/requests/__init__.py
/myapp/requests/adapters.py
etc...

then within main.py put something like

import webapp2
import requests

class MainHandler(webapp2.RequestHandler):
    def get(self):
        g = requests.get('http://www.google.com')
        self.response.write(g.text)

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

这篇关于Python请求模块 - Google App Engine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆