Top-rated recipes tagged "cgi"http://code.activestate.com/recipes/tags/cgi/top/2016-11-01T02:27:13-07:00ActiveState Code RecipesJasperServer.cgi. It works (Python) 2009-11-28T10:34:40-08:00Martchenkohttp://code.activestate.com/recipes/users/4172446/http://code.activestate.com/recipes/576970-jasperservercgi-it-works/ <p style="color: grey"> Python recipe 576970 by <a href="/recipes/users/4172446/">Martchenko</a> (<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/jasperreports/">jasperreports</a>, <a href="/recipes/tags/snippet/">snippet</a>). Revision 2. </p> <p>running jasperreports over pythons CGI</p> "Smart" Links (Python) 2012-07-03T05:05:39-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/440647-smart-links/ <p style="color: grey"> Python recipe 440647 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>The following allows someone to create "smart" links on their web site. This is just a simple system and is not very advanced, but it works quite well (given its purpose). If a link is not active (because a server is down), the link is shown as such.</p> Check web page exists (Python) 2001-12-06T18:47:01-08:00andy mckayhttp://code.activestate.com/recipes/users/92886/http://code.activestate.com/recipes/101276-check-web-page-exists/ <p style="color: grey"> Python recipe 101276 by <a href="/recipes/users/92886/">andy mckay</a> (<a href="/recipes/tags/cgi/">cgi</a>). Revision 4. </p> <p>For when you need to check a web page is still working.</p> Traceback that does'nt output on sys.stderr (Python) 2001-06-25T04:25:48-07:00Dirk Holtwickhttp://code.activestate.com/recipes/users/98196/http://code.activestate.com/recipes/65332-traceback-that-doesnt-output-on-sysstderr/ <p style="color: grey"> Python recipe 65332 by <a href="/recipes/users/98196/">Dirk Holtwick</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>For CGI programmers it's important to display tracebacks in the HTML pages to debug their scripts, but the usual functions in the modules cgi and traceback print to sys.sterr. So this small programm returns the traceback as a string an can even add entities for HTML.</p> stupid trick: mimicking the python cgi library's FieldStorage() object for command line debuging (Python) 2015-06-18T20:46:32-07:00Jon Crumphttp://code.activestate.com/recipes/users/4174917/http://code.activestate.com/recipes/579069-stupid-trick-mimicking-the-python-cgi-librarys-fie/ <p style="color: grey"> Python recipe 579069 by <a href="/recipes/users/4174917/">Jon Crump</a> (<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/urls/">urls</a>). Revision 6. </p> <p>create dictionary-like object that mimics the cgi.FieldStorage() object having both a <code>.value</code> property, and a <code>.getvalue()</code> method</p> Get user's IP address even when they're behind a proxy (Python) 2011-07-15T21:19:17-07:00Ben Hoythttp://code.activestate.com/recipes/users/4170919/http://code.activestate.com/recipes/577795-get-users-ip-address-even-when-theyre-behind-a-pro/ <p style="color: grey"> Python recipe 577795 by <a href="/recipes/users/4170919/">Ben Hoyt</a> (<a href="/recipes/tags/address/">address</a>, <a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/ip/">ip</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/webpy/">webpy</a>). </p> <p>Function to get the user's IP address in a web app or CGI script, even when they're behind a web proxy.</p> <p>We use web.py as our web framework, but change web.ctx.env and web.ctx.get('ip') to whatever the equivalents are for the CGI environment variables and REMOTE_ADDR are in your framework.</p> Python Sessions (Python) 2011-01-08T03:23:05-08:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577524-python-sessions/ <p style="color: grey"> Python recipe 577524 by <a href="/recipes/users/4174115/">Sunjay Varma</a> (<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/cookie/">cookie</a>, <a href="/recipes/tags/management/">management</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/security/">security</a>, <a href="/recipes/tags/sessions/">sessions</a>). Revision 2. </p> <p>I think this script should now be functional enough to post here at ActiveState. When you reply or vote down, please post some information on your problem with the code, and if you can, maybe something about the solution. This interface works, and is designed especially for Python. If you like it, don't be afraid to post that either, constructive criticism is all good, but compliments are even better! ;)</p> <p>Get the latest version of this code here: <a href="http://wiki.sunjay.ca/Python:Contents/Python_Session" rel="nofollow">http://wiki.sunjay.ca/Python:Contents/Python_Session</a></p> <p><strong>Latest Changes:</strong></p> <ul> <li>Added a new function for making the session cookie last longer. See code for <code>set_expires</code>. Note: This new function is just in case you need to include a session for longer than one brower session (for example, one day instead). </li> </ul> Userfriendly Webpage Template (Python) 2010-05-04T07:38:03-07:00david.gaarenstroomhttp://code.activestate.com/recipes/users/4168848/http://code.activestate.com/recipes/577203-userfriendly-webpage-template/ <p style="color: grey"> Python recipe 577203 by <a href="/recipes/users/4168848/">david.gaarenstroom</a> (<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/httpserver/">httpserver</a>, <a href="/recipes/tags/mvc/">mvc</a>, <a href="/recipes/tags/template/">template</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/webdesign/">webdesign</a>, <a href="/recipes/tags/webpagetemplate/">webpagetemplate</a>). Revision 5. </p> <p>User friendly template class targeted towards Web-page usage and optimized for speed and efficiency.</p> <p>Tags can be inserted in a template HTML file in a non-intrusive way, by using specially formatted comment strings. Therefore, the template-file can be viewed in a browser, even with prototype data embedded in it, which will later be replaced by dynamic content. Also, webdesigners can continue to work on the template and upload it without further modification.</p> ExecSql.cgi returning JSON for SQL (Python) 2009-11-28T02:00:30-08:00Martchenkohttp://code.activestate.com/recipes/users/4172446/http://code.activestate.com/recipes/576971-execsqlcgi-returning-json-for-sql/ <p style="color: grey"> Python recipe 576971 by <a href="/recipes/users/4172446/">Martchenko</a> (<a href="/recipes/tags/cgi/">cgi</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/sql/">sql</a>). </p> <p>CGI script getting JSON for SQL request</p> Easy testing of CGI scripts (Python) 2016-11-01T02:27:13-07:00Bryan Olsonhttp://code.activestate.com/recipes/users/1998252/http://code.activestate.com/recipes/550822-easy-testing-of-cgi-scripts/ <p style="color: grey"> Python recipe 550822 by <a href="/recipes/users/1998252/">Bryan Olson</a> (<a href="/recipes/tags/cgi/">cgi</a>). Revision 3. </p> <p>Invoking 'runcgi.py target.cgi' starts a built-in web server listening on the localhost adapter, configures the server to run target.cgi as a CGI program, then launches the system's default web browser to get the URL of the target script. The CGI script need not be in Python. The terminal that launched runcgi.py will show the server's log, which reports requests, responses, and errors.</p> SingleUpload.py (Python) 2010-02-24T13:50:27-08:00Wilhelm Shenhttp://code.activestate.com/recipes/users/4061228/http://code.activestate.com/recipes/521897-singleuploadpy/ <p style="color: grey"> Python recipe 521897 by <a href="/recipes/users/4061228/">Wilhelm Shen</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>Usage:</p> <pre class="prettyprint"><code>#!/usr/bin/env python2.5 # # html file: # &lt;form action="test.cgi" method="POST" enctype="multipart/form-data"&gt; # &lt;input name="file1" type="file"&gt;&lt;input type="submit"&gt;&lt;/form&gt; # test.cgi: ... import SingleUpload def upload(): fr = SingleUpload.open() fw = open('/tmp/%s' %fr.filename, 'wb') while True: l = fr.read(65536) if not l: break fw.write(l) fw.flush() fw.close() print 'Content-Type: text/plain\r\n\r\n' try: upload() print 'OK' except IOError: __import__('traceback').print_exc( file=__import__('sys').stdout ) </code></pre> An asynchronous HTTP server with CGI support (Python) 2007-04-05T05:46:26-07:00Pierre Quentelhttp://code.activestate.com/recipes/users/1552957/http://code.activestate.com/recipes/511454-an-asynchronous-http-server-with-cgi-support/ <p style="color: grey"> Python recipe 511454 by <a href="/recipes/users/1552957/">Pierre Quentel</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>This recipes implements the HTTP protocol with persistent connection and CGI support on top of the generic asynchronous server provided in <a href="http://code.activestate.com/recipes/511453/">recipe 511453</a></p> Paypal IPN (Python) 2006-09-19T19:02:54-07:00Anthony Barkerhttp://code.activestate.com/recipes/users/122940/http://code.activestate.com/recipes/456361-paypal-ipn/ <p style="color: grey"> Python recipe 456361 by <a href="/recipes/users/122940/">Anthony Barker</a> (<a href="/recipes/tags/cgi/">cgi</a>). Revision 2. </p> <p>This is a cgi script that allows you to log an ipn request from paypal. Basically if you configure your paypal account with an ipn url it will send a post to a script url. You need to respond with a post and then will receive a VERIFIED response.</p> <p>I've included a subroutine to log the data to a database, but you could simply use a text file if that is all you need.</p> Python Script Viewer (Python) 2005-10-03T18:17:11-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/440642-python-script-viewer/ <p style="color: grey"> Python recipe 440642 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>First of all, this code was written to take advantage of the custom CGI module that I wrote. The purpose for this script is to allow someone to view a CGI script through a server. I have the problem that when I click on a python (*.py) file while viewed through my browser, the script is run so that it cannot be viewed. Unless the script is using "cgi.execute(function, exception)", then there is no way of getting around the problem. Therefore, this CGI application was written so that python files (and only *.py files) can be viewed if the user knows either the filename of a file in the same directory as this script or the full path of a file somewhere on the host computer. WARNING: do not use this script if you do not want someone to view any and all python scripts on your computer!</p> Custom Made CGI Module (Python) 2005-10-03T18:06:32-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/440641-custom-made-cgi-module/ <p style="color: grey"> Python recipe 440641 by <a href="/recipes/users/2608421/">Stephen Chappell</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>I found the CGI module to be nice in its power but wanted to create my own simpler version of the module. It lacks some of the power that the CGI module affords, but the code is small and has some helpful functions defined in it. The module listed below has been tested but really needs some test code written for it.</p> A very simple session handling example (Python) 2004-10-28T10:38:30-07:00Jonas Galvezhttp://code.activestate.com/recipes/users/2122857/http://code.activestate.com/recipes/325484-a-very-simple-session-handling-example/ <p style="color: grey"> Python recipe 325484 by <a href="/recipes/users/2122857/">Jonas Galvez</a> (<a href="/recipes/tags/cgi/">cgi</a>). Revision 4. </p> <p>This is a very simple session handling example that uses plain Python CGI (tested only under Python 2.2+). Its goal is to show how cookies are set via HTTP and how easily they can be used for session management.</p> webcounter (Python) 2004-10-15T05:33:47-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/310320-webcounter/ <p style="color: grey"> Python recipe 310320 by <a href="/recipes/users/1565518/">Michael Foord</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>This CGI will generate a simple text 'hit counter' for several sites. Useful to ocunt visitors to the 'front door' of your website.</p> http - Exploring Headers and Cookies from Servers (Python) 2004-08-18T10:23:52-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/298336-http-exploring-headers-and-cookies-from-servers/ <p style="color: grey"> Python recipe 298336 by <a href="/recipes/users/1565518/">Michael Foord</a> (<a href="/recipes/tags/cgi/">cgi</a>). Revision 5. </p> <p>This CGI script allows you to specify a URL. It fetches the URL and displays all the headers sent by the server. It is based on approx.py the CGI-proxy I'm building. It includes authentication circuitry and I'm using it to understand http authentication.</p> <p>This script demostrates using urllib2 to fetch a URL - using a request object with User-Agent header. It also demostrates basic authentication and shows the possible http errors - using a dictionary 'borrowed' from BaseHTTPServer.</p> <p>It will also save cookies using the ClientCookie module, if it's available.</p> cgi-shell (Python) 2004-07-09T07:31:52-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/286217-cgi-shell/ <p style="color: grey"> Python recipe 286217 by <a href="/recipes/users/1565518/">Michael Foord</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>Run an arbitrary string on the server as a shell command. Mimics a very basic shell environment on a server using CGI.</p> cgi-shell (Python) 2004-07-09T07:30:50-07:00Michael Foordhttp://code.activestate.com/recipes/users/1565518/http://code.activestate.com/recipes/286216-cgi-shell/ <p style="color: grey"> Python recipe 286216 by <a href="/recipes/users/1565518/">Michael Foord</a> (<a href="/recipes/tags/cgi/">cgi</a>). </p> <p>Run an arbitrary string on the server as a shell command. Mimics a very basic shell environment on a server using CGI.</p>