473,547 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using "request" variable in python web program

Hi

I am trying to write a facebook application in python - I have been
programming simple desktop applications till now and am not really
familiar with web apps

Pyfacebook is the wrapper for the REST based Facebook API - there is a
simple example for its usage as shown below:

def simple_web_app( request, api_key, secret_key):
fb = Facebook(api_ke y, secret_key, request.GET['auth_token'])
fb.auth_getSess ion()

A Django-based tutorial and source is available here:
http://wiki.developers.facebook.com/...cebookTutorial

I really don't want to use a framework for the time being and just
want an app up and running

My question is - how do you create the "request" object which will be
passed into the simple_web_app( request, api_key, secret_key) function
here - is there somewhere I can read into it?

I have been googling for hours and there seems to be no simple,
straightforward example for this - PHP rules when it comes to simple
web programming apps - either I am not looking at the right places but
it's very hard to get up and running quickly for web apps in Python -
maybe DiveIntoPython needs a section devoted for web programming

Oct 20 '07 #1
7 2454
On 21 Okt, 00:21, sami <sami....@gmail .comwrote:
>
def simple_web_app( request, api_key, secret_key):
fb = Facebook(api_ke y, secret_key, request.GET['auth_token'])
fb.auth_getSess ion()

A Django-based tutorial and source is available here:http://wiki.developers.facebook.com/...cebookTutorial

I really don't want to use a framework for the time being and just
want an app up and running
Something like CGI, mod_python or Python's standard library
BaseHTTPServer might be good enough. Or you could try WebStack if you
can't decide. See these links for details:

http://wiki.python.org/moin/CgiScripts
http://www.modpython.org/
http://wiki.python.org/moin/BaseHttpServer
http://www.python.org/pypi/WebStack
My question is - how do you create the "request" object which will be
passed into the simple_web_app( request, api_key, secret_key) function
here - is there somewhere I can read into it?
The request object in this case is specifically a Django request
object; this can be deduced from usage of the request.GET attribute
which is specific to Django. If you decided to use another framework,
you'd need to rewrite this part; for example in WebStack...

class FacebookResourc e:
def respond(self, trans):
try:
auth_token = trans.get_field s_from_path()['auth_token'][0]
fb = Facebook(api_ke y, secret_key, auth_token)
fb.auth_getSess ion()
...
except KeyError: # no auth token
...

I'm sure others can suggest their own preferred solutions.
I have been googling for hours and there seems to be no simple,
straightforward example for this - PHP rules when it comes to simple
web programming apps - either I am not looking at the right places but
it's very hard to get up and running quickly for web apps in Python -
maybe DiveIntoPython needs a section devoted for web programming
There's only consensus around WSGI as some kind of standard in Python
Web programming, but it isn't likely to get you very far without
forcing you to choose extra components to make the work bearable (eg.
to read query/form values), so it isn't the one way of doing things at
the level that PHP presumably offers (which is why it's presumably
easier to find advice on such matters all over the Web for PHP).

Most people advocate particular frameworks instead of WSGI, and as
you've noticed people do seem to like Django quite a lot. The problem
with this state of affairs is that you need to make "up front" choices
when testing out frameworks, and after the legwork of setting stuff
up, if you don't like what you've seen you've got to back out and do
similar (but different) stuff for your next choice of framework.

However, it shouldn't be too bad to set Django up, really, especially
if people have taken some time to explain something very close to what
you want to do using Django. Moreover, there's a Google group (django-
users) where you could ask general questions, and I imagine that
people will be quite happy to help you out. But I can totally
understand that creating databases and installing various packages
seems somewhat peripheral to a task which could arguably be done using
a CGI script (as far as I can see).

Paul

P.S. I'm not too impressed by the lack of a common high-level Web API
for Python, either. However, I've mostly ignored the discussions and
stuck with my own API (WebStack) in the knowledge that if it doesn't
work for me, at least I know how I might fix it.

Oct 21 '07 #2
However, it shouldn't be too bad to set Django up, really, especially
if people have taken some time to explain something very close to what
you want to do using Django. Moreover, there's a Google group (django-
users) where you could ask general questions, and I imagine that
people will be quite happy to help you out. But I can totally
understand that creating databases and installing various packages
seems somewhat peripheral to a task which could arguably be done using
a CGI script (as far as I can see).
Thanks a ton Paul for the information. I am using CGI and my host
(nearlyfreespee ch.net) does not have django hosting - and being mainly
a C/dekstop apps programmer I really don't want to learn the whole MVC
concept and its implementation (and quirks) in django - I want to use
abstractions only when I feel the need for them

Since a django user made pyfacebook, hopefully someone on the forum
will help out

Thanks again

Sami
Paul

P.S. I'm not too impressed by the lack of a common high-level Web API
for Python, either. However, I've mostly ignored the discussions and
stuck with my own API (WebStack) in the knowledge that if it doesn't
work for me, at least I know how I might fix it.

Oct 21 '07 #3
On 21 Okt, 21:59, sami <sami....@gmail .comwrote:
>
Thanks a ton Paul for the information. I am using CGI and my host
(nearlyfreespee ch.net) does not have django hosting - and being mainly
a C/dekstop apps programmer I really don't want to learn the whole MVC
concept and its implementation (and quirks) in django - I want to use
abstractions only when I feel the need for them
See the library reference for information on how to get the value of
form/request parameters from the CGI environment:

http://docs.python.org/lib/node561.html

Paul

Oct 21 '07 #4
See the library reference for information on how to get the value of
form/request parameters from the CGI environment:

http://docs.python.org/lib/node561.html

Paul
Thanks again Paul - now I can see that the "request" object is a
string of name/value pairs that occurs after a "?" in a url e.g.
url.com/index.cgi?name= sami&lang=pytho n - is that correct? Googling
for this information is useless since the word "request" is so common
on the www

Oct 22 '07 #5
On 22 Okt, 10:34, sami <sami....@gmail .comwrote:
See the library reference for information on how to get the value of
form/request parameters from the CGI environment:
http://docs.python.org/lib/node561.html
Paul

Thanks again Paul - now I can see that the "request" object is a
string of name/value pairs that occurs after a "?" in a url e.g.
url.com/index.cgi?name= sami&lang=pytho n - is that correct? Googling
for this information is useless since the word "request" is so common
on the www
The string after "?" in a URL is actually the "query string" and is
typically exposed as the QUERY_STRING environment variable in CGI. See
here for more specific details:

http://www.w3.org/CGI/
http://cgi-spec.golux.com/

What the cgi module provides is some conveniences for automatically
decoding the query string - perhaps not *so* difficult, you might
think, even taking the decoding of encoded values into account (such
as things like "%20" that you find in URLs) - but the cgi module also
provides facilities to decode request parameters that are supplied in
the body of a request (such as those provided in POST requests), and
that can be a more difficult exercise.

Paul

Oct 22 '07 #6
En Mon, 22 Oct 2007 05:34:55 -0300, sami <sa******@gmail .comescribi�:
Thanks again Paul - now I can see that the "request" object is a
string of name/value pairs that occurs after a "?" in a url e.g.
url.com/index.cgi?name= sami&lang=pytho n - is that correct? Googling
for this information is useless since the word "request" is so common
on the www
Not exactly - this is the "query string" part of the URI.
Request and Response are the two messages defined by the HTTP protocol.
When you type a URL or click on a link or press a button in a page, your
browser builds the appropiate Request message and sends it to the server.
After processing, the server emits the Response message, and the browser
displays it or otherwise processes the response.
The request and response objects that most web frameworks expose are
abstractions of these two HTTP messages.
The bloody details are specified in RFC 2616 HTTP/1.1
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html>, but you can find
plenty of less technical descriptions. At least a basic understanding of
how the HTTP protocol works is required to build a web application.

--
Gabriel Genellina

Oct 22 '07 #7
Not exactly - this is the "query string" part of the URI.
Request and Response are the two messages defined by the HTTP protocol.
When you type a URL or click on a link or press a button in a page, your
browser builds the appropiate Request message and sends it to the server.
After processing, the server emits the Response message, and the browser
displays it or otherwise processes the response.

--
Gabriel Genellina
Thanks Paul and Gabriel - I am confused I guess - I do know about the
request/response mechanism, I wrote this app a while ago:
http://aspn.activestate.com/ASPN/Coo.../Recipe/522983 - I
wrote this app before in C and decoded request/response params using a
sniffer - I ported it to Python since I wanted to learn Python
The string after "?" in a URL is actually the "query string" and is
typically exposed as the QUERY_STRING environment variable in CGI. See
here for more specific details:
This is what is mixing me up - an example given in the source for
Pyfacebook - http://pyfacebook.googlecode.com/svn...es/examples.py

def simple_web_app( request, api_key, secret_key):
fb = Facebook(api_ke y, secret_key, request.GET['auth_token'])
fb.auth.getSess ion()

It seemed to me "request" was a key in a key/value pair string/
dictionary

Anyway, I have the "auth_token " now and I can pass these 3 string
values to as Facebook(<api_k ey>, <secret_key>, <auth_token>) - and
it's moving along - but I am persevering :) no PHP for me - I hope I
can put up a tut for this afterwards

Thanks again for the help, guys

Oct 22 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2209
by: Sam Sungshik Kong | last post by:
Hello! I use Python for ASP programming. I found something weird. Response.Write(Request("something")) It draws "None" when there's no value for something. Actually I expect "" instead of "None". So I changed it like
32
4106
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:"...
0
3186
by: Ian Staines | last post by:
In asp the following code: Request.Servervarables("AUTH_USER") will return the header variable AUTH_USER In .NET the code Request.Servervariables("AUTH_USER") returns the server variable AUTH_USER, but if you want the header variable you must request it with Request.Headers("AUTH_USER")
0
1676
by: . | last post by:
http://daviderognoni.blogspot.com?locawapp - MAIN NEWS =========== * add thread * add "Request" object * new "locawapp_main" function * fixed files.py
25
2552
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For example: with quitCommandButton .enabled = true .default = true end with
0
7510
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7437
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7703
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7797
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6032
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1923
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.