473,287 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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_key, secret_key, request.GET['auth_token'])
fb.auth_getSession()

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 2436
On 21 Okt, 00:21, sami <sami....@gmail.comwrote:
>
def simple_web_app(request, api_key, secret_key):
fb = Facebook(api_key, secret_key, request.GET['auth_token'])
fb.auth_getSession()

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 FacebookResource:
def respond(self, trans):
try:
auth_token = trans.get_fields_from_path()['auth_token'][0]
fb = Facebook(api_key, secret_key, auth_token)
fb.auth_getSession()
...
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
(nearlyfreespeech.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
(nearlyfreespeech.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=python - 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=python - 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=python - 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_key, secret_key, request.GET['auth_token'])
fb.auth.getSession()

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_key>, <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
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...
32
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...
0
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...
0
by: . | last post by:
http://daviderognoni.blogspot.com?locawapp - MAIN NEWS =========== * add thread * add "Request" object * new "locawapp_main" function * fixed files.py
25
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...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.