Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how do I instantiate the request class

Posted on 2010-11-21
8
Medium Priority
?
445 Views
Last Modified: 2012-05-10
The Request constructor requires a parameter called environ which I have no clue as to how to code.
0
Comment
Question by:blueshoes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 15

Expert Comment

by:mish33
ID: 34185377
You don't need to. GAE will create it for you and you just access request object.
0
 

Author Comment

by:blueshoes
ID: 34185573
So how do I get a reference to it to access it? Is there something I have to import?

I have a WSGIGateway  app with a  Python module containing methods implementing various services (RPCs).In some of those methods I need the remote_addr property from the Request object. How can I get a reference to the Request object in order to reference that property?  Is there perhaps a way that the Request object can be passed as a parameter to those methods?
0
 
LVL 15

Expert Comment

by:mish33
ID: 34185622
If you use weapp framework (http://code.google.com/appengine/docs/python/gettingstarted/usingwebapp.html) it's available as self.request
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 

Author Comment

by:blueshoes
ID: 34187458
I am implementing the client side of my app with Flex. I am not much conversant with Python or Google App Engine and am sort of stumbling through the server side of my app. Here are a couple of facts about my situation. 1) I am using a product called PyAMF that implements the Adobe Action Message Format, and 2) I have been advised by a consultant on this project who set up my Google App Engine framework. Most of the app is coded and running in a test environment. Recently I had a need to get the remote_addr property of the Request object, and that  is where this particular problem came about.

My app.py has the following imports.
import wsgiref.handlers
from pyamf.remoting.gateway.wsgi import WSGIGateway
from models import utils
from services import data_services
So I suppose that PyAMF dictates that I use its WSGIGateway, but I don't know enough about it to know for sure. In any case, referencing self.request gives the following error.
AttributeError: 'DataServices' object has no attribute 'request'
Somebody advised me to use a Python decorator that would pass the Request object to a method as an added first parameter (after self) as follows.
@expose_request
def userSignIn(self, request, sessionKey, userSigninName, clientPasswordHash):
Subsequent reference to request.remote_addr gives an error saying that request is a dictionary and has no attribute remote_addr.

Given all that, do you know how I can get at the remote_addr property?
0
 
LVL 15

Accepted Solution

by:
mish33 earned 2000 total points
ID: 34201354
Try request['remote_addr']

If it fails, print request.keys() and see if it spelled differently.
0
 

Author Comment

by:blueshoes
ID: 34215482
Re: Try request['remote_addr']

The only thing about that suggestion that was needed was to change the string literal to uppercase: request['REMOTE_ADDR']

Thanks!
0
 

Author Comment

by:blueshoes
ID: 34215520
Re: If it fails, print request.keys() and see if it spelled differently.

I tried this by literally inserting the statement print request.keys() into my code. I am testing my app with Google App Engine Launcher, and I thought maybe the output of that statement would be directed to the log, but it wasn't. How would I do that? Where would the output appear?
0
 
LVL 15

Expert Comment

by:mish33
ID: 34218592
The output should be in the logs. To produce on browser use something like
response.write(request.keys())
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question