Radha Kapoor
Radha Kapoor

Reputation: 271

Python Request Module - Google App Engine

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?

Upvotes: 4

Views: 4349

Answers (2)

Bryan
Bryan

Reputation: 126

You need to add the requests/requests sub-folder to your project. From your script's location (.), you should see a file at ./requests/__init__.py.

This applies to all modules you include for Google App Engine. If it doesn't have a __init__.py directly under that location, it will not work.

You do not need to add the module to app.yaml.

Upvotes: 0

user714852
user714852

Reputation: 2154

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)

Upvotes: 11

Related Questions