4

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?

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Radha Kapoor
  • 271
  • 2
  • 6
  • 14

2 Answers2

11

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)
user714852
  • 2,054
  • 4
  • 30
  • 52
  • Thank you so much! Sorry for the basic question (I haven't been at this very long) but how do I do that from Git? There are so many files I don't know what to use. – Radha Kapoor Jun 15 '13 at 22:21
  • @RadhaKapoor you have to actually copy it into the folder directly. – Jeff Tratner Jun 15 '13 at 22:43
  • @RadhaKapoor it's probably simpler to just download the requests library from https://github.com/kennethreitz/requests/archive/master.zip unzip it and stick the requests directory into your appengine folder. – user714852 Jun 16 '13 at 14:00
  • @user714852 so I literally just dragged and dropped the entire requests folder you linked to into my web app project folder. I'm still getting the same error ie "no module named requests". Did I put it in the wrong folder - did you mean something different? Thank you again - I really appreciate it. – Radha Kapoor Jun 17 '13 at 14:28
  • have you put "import requests" before you call the library? – user714852 Jun 17 '13 at 19:06
  • in main.py i have included the following at the top of the file: **from google.appengine.ext import db, import webapp2, import os, import jinja2, import requests, import json, import logging** – Radha Kapoor Jun 17 '13 at 19:16
  • I've put in some detail in the answer above which should solve your problem hopefully. – user714852 Jun 17 '13 at 21:46
0

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.

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Bryan
  • 116
  • 4