Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   parse GET/POST data on simple http server (http://www.velocityreviews.com/forums/t743024-parse-get-post-data-on-simple-http-server.html)

Markus 02-03-2011 08:15 AM

parse GET/POST data on simple http server
 
Hi,

As a beginner in python, I am looking for example code that would help
me understand how to
code following idea:
1. Start minimal http server
2. Send GET or POST data (url encoded, or from form) - example
Name="Foo"
3. Analyze the GET/POST variable value on server and match to
different value
example 'if Name = "Foo" then retval = "Bar" '
4. serve the content of retval back to user as plain html

If some code snipped that does implement all or part of the algorithm
is known to you, please point me to it. I would be thankful for any
push to the right direction.

Thank you!

Corey Richardson 02-03-2011 08:26 AM

Re: parse GET/POST data on simple http server
 
On 02/03/2011 03:15 AM, Markus wrote:
> Hi,
>
> As a beginner in python, I am looking for example code that would help
> me understand how to
> code following idea:
> 1. Start minimal http server
> 2. Send GET or POST data (url encoded, or from form) - example
> Name="Foo"
> 3. Analyze the GET/POST variable value on server and match to
> different value
> example 'if Name = "Foo" then retval = "Bar" '
> 4. serve the content of retval back to user as plain html
>
> If some code snipped that does implement all or part of the algorithm
> is known to you, please point me to it. I would be thankful for any
> push to the right direction.
>
> Thank you!


If you really can't use a 'real' webserver like Apache, I found [1]. Not
sure how to use it, never had the need to. The documentation will show
you the way, however. Using that and the cgi module, your requirements
should be fulfilled.

Corey Richardson 02-03-2011 08:26 AM

Re: parse GET/POST data on simple http server
 
On 02/03/2011 03:15 AM, Markus wrote:
> Hi,
>
> As a beginner in python, I am looking for example code that would help
> me understand how to
> code following idea:
> 1. Start minimal http server
> 2. Send GET or POST data (url encoded, or from form) - example
> Name="Foo"
> 3. Analyze the GET/POST variable value on server and match to
> different value
> example 'if Name = "Foo" then retval = "Bar" '
> 4. serve the content of retval back to user as plain html
>
> If some code snipped that does implement all or part of the algorithm
> is known to you, please point me to it. I would be thankful for any
> push to the right direction.
>
> Thank you!


[1] http://docs.python.org/library/cgiht...-CGIHTTPServer

....Sorry about that. I shouldn't post late at night!

Chris Rebert 02-03-2011 08:35 AM

Re: parse GET/POST data on simple http server
 
On Thu, Feb 3, 2011 at 12:15 AM, Markus <markus.mj@gmail.com> wrote:
> Hi,
>
> As a beginner in python, I am looking for example code that would help
> me understand how to
> code following idea:
> 1. Start minimal http server


http://docs.python.org/library/basehttpserver.html
http://docs.python.org/library/simplehttpserver.html
http://docs.python.org/library/cgihttpserver.html

> 2. Send GET or POST data (url encoded, or from form) - example
> Name="Foo"


http://docs.python.org/library/urlli...llib.urlencode

> 3. Analyze the GET/POST variable value on server and match to
> different value
> * *example 'if Name = "Foo" then retval = "Bar" '


http://docs.python.org/library/cgi.html

> 4. serve the content of retval back to user as plain html
>
> If some code snipped that does implement all or part of the algorithm
> is known to you, please point me to it. I would be thankful for any
> push to the right direction.


You'll be reinventing quite a few wheels if you work at such a low
level of abstraction. Have you considered using a web framework?
Django (http://www.djangoproject.com/ ) is one of the popular ones,
though there are a myriad of options
(http://wiki.python.org/moin/WebFrameworks ). I would recommend
learning Python first and then a web framework, rather than trying to
learn both in tandem.

Cheers,
Chris
--
http://blog.rebertia.com

Markus 02-03-2011 08:52 AM

Re: parse GET/POST data on simple http server
 
On Feb 3, 9:35*am, Chris Rebert <c...@rebertia.com> wrote:
> On Thu, Feb 3, 2011 at 12:15 AM, Markus <markus...@gmail.com> wrote:
> > Hi,

>
> > As a beginner in python, I am looking for example code that would help
> > me understand how to
> > code following idea:
> > 1. Start minimal http server

>
> http://docs.python.org/library/baseh...ttpserver.html
>
> > 2. Send GET or POST data (url encoded, or from form) - example
> > Name="Foo"

>
> http://docs.python.org/library/urlli...llib.urlencode
>
> > 3. Analyze the GET/POST variable value on server and match to
> > different value
> > * *example 'if Name = "Foo" then retval = "Bar" '

>
> http://docs.python.org/library/cgi.html
>
> > 4. serve the content of retval back to user as plain html

>
> > If some code snipped that does implement all or part of the algorithm
> > is known to you, please point me to it. I would be thankful for any
> > push to the right direction.

>
> You'll be reinventing quite a few wheels if you work at such a low
> level of abstraction. Have you considered using a web framework?
> Django (http://www.djangoproject.com/) is one of the popular ones,
> though there are a myriad of options
> (http://wiki.python.org/moin/WebFrameworks). I would recommend
> learning Python first and then a web framework, rather than trying to
> learn both in tandem.
>
> Cheers,
> Chris
> --http://blog.rebertia.com


Thank you for all that input, I will definitely check Django - it
looks very interesting.
I just found an example code that fits perfectly and is simple enough
for me to play with it.
http://stackoverflow.com/questions/3...ajax-in-python
And one older post handling the same case with HTTPS:
http://groups.google.com/group/comp....f6f704b3a6749a

:o)


All times are GMT. The time now is 08:28 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.