Jeff Peery | 5 Nov 02:14 2007
Picon

how to post from a cgi script and not a html form??

hello,
I'm pretty new to using python on the web, I've got a bit of code that works pretty well to get form inputs and such. Now I need to post some info to a gateway service (for credit card processing) and then receive their response and do something with it. I can do this no problem... except that I'm not sure how to post my dictionary (name value pairs from form inputs i.e., credit card num, expire dates etc) from the cgi script. I had been using the html forms to submit data to the server, but now I need to do this from my cgi script. I think this is pretty straight forward but I didn't see anything in the cgi module. where do I start, or does anyone have some sample code? thanks!!
 
Jeff

_____________________________________ _____________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org
Alex Botero-Lowry | 5 Nov 03:38 2007

Re: how to post from a cgi script and not a html form??

On Sun, Nov 04, 2007 at 05:14:31PM -0800, Jeff Peery wrote:
> hello, 
>   I'm pretty new to using python on the web, I've got a bit of code 
> that works pretty well to get form inputs and such. Now I need to post 
> some info to a gateway service (for credit card processing) and then 
> receive their response and do something with it. I can do this no 
> problem... except that I'm not sure how to post my dictionary (name 
> value pairs from form inputs i.e., credit card num, expire dates etc) 
> from the cgi script. I had been using the html forms to submit data to 
> the server, but now I need to do this from my cgi script. I think this is 
> pretty straight forward but I didn't see anything in the cgi module. 
> where do I start, or does anyone have some sample code? thanks!!

You'll need httplib which luckily come with the stdlib so no need to install 
anything.

Something like this should get you going:

conn = httplib.HTTPConnection(remote_server)
values = '&'.join([ '%s=%s' % a for a in values.items() ])
headers={'Content-Type':'application/x-www-form-urlencoded'}
conn.request(method, url, values, headers=headers)
res = conn.getresponse()
data = res.read()
return (res.status, res.reason, output)

the important bits here are our crappy makeshift 
application/x-www-form-urlencoded rncoder which
is the values line and our setting of the content-type. We also 
need to make sure the method passed to conn.request is 'POST' or 
'PUT' (almost certainly POST) as these are the only ones that accept 
a body. I think the cgi module may have a better way of doing the 
encoding, but i've never found it.

Alex
_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Graham Dumpleton | 5 Nov 04:08 2007
Picon

Re: how to post from a cgi script and not a html form??

On 05/11/2007, Alex Botero-Lowry
<alex@...> wrote:
> On Sun, Nov 04, 2007 at 05:14:31PM -0800, Jeff Peery wrote:
> > hello,
> >   I'm pretty new to using python on the web, I've got a bit of code
> > that works pretty well to get form inputs and such. Now I need to post
> > some info to a gateway service (for credit card processing) and then
> > receive their response and do something with it. I can do this no
> > problem... except that I'm not sure how to post my dictionary (name
> > value pairs from form inputs i.e., credit card num, expire dates etc)
> > from the cgi script. I had been using the html forms to submit data to
> > the server, but now I need to do this from my cgi script. I think this is
> > pretty straight forward but I didn't see anything in the cgi module.
> > where do I start, or does anyone have some sample code? thanks!!
>
> You'll need httplib which luckily come with the stdlib so no need to install
> anything.
>
> Something like this should get you going:
>
> conn = httplib.HTTPConnection(remote_server)
> values = '&'.join([ '%s=%s' % a for a in values.items() ])

>From memory, better off using urllib.urlencode() for this as it will
properly quote and convert special characters.

> headers={'Content-Type':'application/x-www-form-urlencoded'}
> conn.request(method, url, values, headers=headers)
> res = conn.getresponse()
> data = res.read()
> return (res.status, res.reason, output)
>
> the important bits here are our crappy makeshift
> application/x-www-form-urlencoded rncoder which
> is the values line and our setting of the content-type. We also
> need to make sure the method passed to conn.request is 'POST' or
> 'PUT' (almost certainly POST) as these are the only ones that accept
> a body. I think the cgi module may have a better way of doing the
> encoding, but i've never found it.
>
> Alex
> _______________________________________________
> Web-SIG mailing list
> Web-SIG@...
> Web SIG: http://www.python.org/sigs/web-sig
> Unsubscribe: http://mail.python.org/mailman/options/web-sig/graham.dumpleton%40gmail.com
>
_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Jeff Peery | 5 Nov 05:43 2007
Picon

Re: how to post from a cgi script and not a html form??

Thanks, thats a big help!
 
only two things I don't understand well. when I create a http object with HTTPConnection() do I want this to be to my web host server (hostway.com) or to the server I'm posting to (authorize.net)?
 
and what are the headers used for?
 
again, thanks!
 
Jeff

Graham Dumpleton <graham.dumpleton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
On 05/11/2007, Alex Botero-Lowry wrote:
> On Sun, Nov 04, 2007 at 05:14:31PM -0800, Jeff Peery wrote:
> > hello,
> > I'm pretty new to using python on the web, I've got a bit of code
> > that works pretty well to get form inputs and such. Now I need to post
> > some info to a gateway service (for credit card processing) and then
> > receive their response and do something with it. I can do this no
> > problem... except that I'm not sure how to post my dictionary (name
> > value pairs from form inputs i.e., credit card num, expire dates etc)
> > from the cgi script. I had been using the html forms to submit data to
> > the server, but now I need to do this from my cgi script. I think this is
> > pretty straight forward but I didn't see anything in the cgi module.
> > where do I start, or does anyone have some sample code? thanks!!
>
> You'll need httplib which luckily come with the stdlib so no need to install
> anything.
>
> Something like this should get you going:
>
> conn = httplib.HTTP Connection(remote_server)
> values = '&'.join([ '%s=%s' % a for a in values.items() ])

From memory, better off using urllib.urlencode() for this as it will
properly quote and convert special characters.

> headers={'Content-Type':'application/x-www-form-urlencoded'}
> conn.request(method, url, values, headers=headers)
> res = conn.getresponse()
> data = res.read()
> return (res.status, res.reason, output)
>
> the important bits here are our crappy makeshift
> application/x-www-form-urlencoded rncoder which
> is the values line and our setting of the content-type. We also
> need to make sure the method passed to conn.request is 'POST' or
> 'PUT' (almost certainly POST) as these are the only ones that accept
> a body. I think the cgi module may have a better way of doing the
> encoding, but i've never found it.
>
> Alex
> _________________________________ ______________
> Web-SIG mailing list
> Web-SIG-+ZN9ApsXKcEdnm+yROfE0A@public.gmane.org
> Web SIG: http://www.python.org/sigs/web-sig
> Unsubscribe: http://mail.python.org/mailman/options/web-sig/graham.dumpleton%40gmail.com
>

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org
Alex Botero-Lowry | 5 Nov 06:10 2007

Re: how to post from a cgi script and not a html form??

On Sun, Nov 04, 2007 at 08:43:23PM -0800, Jeff Peery wrote:
> Thanks, thats a big help!
>    
>   only two things I don't understand well. when I create a http object with HTTPConnection() do I want this to
be to my web host server (hostway.com) or to the server I'm posting to (authorize.net)?
>    
The server you are posting to, it's just basically an HTTP client.

>   and what are the headers used for?
>    
It tells it that the content type is application/x-www-form-urlencoded, which
will be checked for on the remote side.

Alex

>   again, thanks!
>    
>   Jeff
> 
> Graham Dumpleton <graham.dumpleton@...> wrote:
>   On 05/11/2007, Alex Botero-Lowry wrote:
> > On Sun, Nov 04, 2007 at 05:14:31PM -0800, Jeff Peery wrote:
> > > hello,
> > > I'm pretty new to using python on the web, I've got a bit of code
> > > that works pretty well to get form inputs and such. Now I need to post
> > > some info to a gateway service (for credit card processing) and then
> > > receive their response and do something with it. I can do this no
> > > problem... except that I'm not sure how to post my dictionary (name
> > > value pairs from form inputs i.e., credit card num, expire dates etc)
> > > from the cgi script. I had been using the html forms to submit data to
> > > the server, but now I need to do this from my cgi script. I think this is
> > > pretty straight forward but I didn't see anything in the cgi module.
> > > where do I start, or does anyone have some sample code? thanks!!
> >
> > You'll need httplib which luckily come with the stdlib so no need to install
> > anything.
> >
> > Something like this should get you going:
> >
> > conn = httplib.HTTPConnection(remote_server)
> > values = '&'.join([ '%s=%s' % a for a in values.items() ])
> 
> >From memory, better off using urllib.urlencode() for this as it will
> properly quote and convert special characters.
> 
> > headers={'Content-Type':'application/x-www-form-urlencoded'}
> > conn.request(method, url, values, headers=headers)
> > res = conn.getresponse()
> > data = res.read()
> > return (res.status, res.reason, output)
> >
> > the important bits here are our crappy makeshift
> > application/x-www-form-urlencoded rncoder which
> > is the values line and our setting of the content-type. We also
> > need to make sure the method passed to conn.request is 'POST' or
> > 'PUT' (almost certainly POST) as these are the only ones that accept
> > a body. I think the cgi module may have a better way of doing the
> > encoding, but i've never found it.
> >
> > Alex
> > _______________________________________________
> > Web-SIG mailing list
> > Web-SIG@...
> > Web SIG: http://www.python.org/sigs/web-sig
> > Unsubscribe: http://mail.python.org/mailman/options/web-sig/graham.dumpleton%40gmail.com
> >
> 
> 
>  __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 

> _______________________________________________
> Web-SIG mailing list
> Web-SIG@...
> Web SIG: http://www.python.org/sigs/web-sig
> Unsubscribe: http://mail.python.org/mailman/options/web-sig/alex%40foxybanana.com

_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Mikeal Rogers | 5 Nov 21:04 2007

Windmill -- Automated WebUI testing framework

The QA Developers at OSAF have been working for some time on Windmill,  
a framework for complete automated WebUI testing across all target  
browsers and all target operating systems. It is course 100% open  
source ( Apache 2 License ) and maintained at the Open Source  
Applications Foundation where it is used to test the Chandler Server  
web interface.

Windmill is implemented in Python (we're a heavy consumer of WSGI )  
and JavaScript.

We just reached 0.2.6 and think it's stable enough for the web world  
at large.

Tomorrow we'll be hosting an IRC Sprint in #windmill of  
irc.freenode.org from 10am to 5pm PST. Please come and join us, we'd  
like to gather your feedback and help with any issues you might  
encounter from install to continuous integration.

http://windmill.osafoundation.org

Hope to see you tomorrow.

-Mikeal
_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Ian Bicking | 10 Nov 19:05 2007

Re: [Paste] GeneratorExit

Jochen Kupperschmidt wrote:
> Hi Ian,
> 
> when using your Paste suite and its HTTP server, I sporadically come 
> across a traceback related to a GeneratorExit. It does not seem to break 
> stuff, but it confuses me and fills up my log.
> 
> I put the traceback, together with some description and related links 
> that might help examining and fixing it, at 
> http://paste.pocoo.org/show/9976/
> It should be easy to fix, as far as I can tell. Please let me know what 
> you think.

I'm guessing this is some interaction between the extensions to the 
generator protocol in Python 2.5, and its overlap with app_iter.close() 
in WSGI.  I'm not sure what the proper behavior here is.  Just swallow 
the error?  Maybe PJE has an idea of what should happen here.

--

-- 
Ian Bicking : ianb@... : http://blog.ianbicking.org
_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Phillip J. Eby | 14 Nov 14:46 2007

Re: [Paste] GeneratorExit

At 12:05 PM 11/10/2007 -0600, Ian Bicking wrote:
>Jochen Kupperschmidt wrote:
> > Hi Ian,
> >
> > when using your Paste suite and its HTTP server, I sporadically come
> > across a traceback related to a GeneratorExit. It does not seem to break
> > stuff, but it confuses me and fills up my log.
> >
> > I put the traceback, together with some description and related links
> > that might help examining and fixing it, at
> > http://paste.pocoo.org/show/9976/
> > It should be easy to fix, as far as I can tell. Please let me know what
> > you think.
>
>I'm guessing this is some interaction between the extensions to the
>generator protocol in Python 2.5, and its overlap with app_iter.close()
>in WSGI.  I'm not sure what the proper behavior here is.  Just swallow
>the error?  Maybe PJE has an idea of what should happen here.

What should happen here is that the person who wrote the generator 
such that it catches and ignores GeneratorExit needs to fix it.  The 
error shown in that traceback is:

"RuntimeError: generator ignored GeneratorExit"

Which means it's the generator that's broken.  It's presumably got a 
try/except block that either doesn't re-raise the error, or that 
contains a yield.

_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Massimo Di Pierro | 15 Nov 00:08 2007
Picon

Gluon 1.12

Hello everybody.

Just wanted to let you know that Gluon 1.12 (GPL2) is out with lots  
of new stuff: better database administrative interface, JSON, CSV,  
RTF, RSS, etc. (find examples in the web page)

     http://mdp.cti.depaul.edu

We also have a google group: http://groups.google.com/group/gluon?hl=en
a wiki: http://www.bithawk.net/cgi-bin/moin.cgi/GluonNotes
a youtube video: http://www.youtube.com/watch?v=VBjja6N6IYk
and a cookbook tutorial: http://mdp.cti.depaul.edu/examples/static/ 
cookbook.pdf
and a sample controller for registration/authentication: http:// 
gluon.googlegroups.com/web/identity.py

Notice: The Linux version requires Python2.5 and sqlite3 or  
postgresql. The Windows and Mac binary version should have no  
dependencies.

Thanks to everybody who is contributing.

Massimo

_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Manlio Perillo | 16 Nov 21:16 2007
Picon

about WSGI adoption

In these days I have to install a Trac instance.

Trac needs a TRAC_ENV variable, and it seems that the only ways to set 
this variable is to:
1) Set the TRAC_ENV environment variable (CGI)
2) Use the TracEnv mod_wsgi option

I found it remarkable that Trac does not has support for WSGI (as an 
example defining a `trac.trac_env` WSGI variable).

This problem is not only present in Trac; Mercurial too uses enviroment 
variables only (as far as I know).

Moreover Trac and Mercurial have a .cgi and a .fcgi script, but not a 
.wsgi script.

What's the cause of this?

Regards  Manlio Perillo
_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org


Gmane