~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-3.5.2-docs-html/library/cgitb.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
3
 
 
4
 
 
5
<html xmlns="http://www.w3.org/1999/xhtml">
 
6
  <head>
 
7
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
8
    
 
9
    <title>21.3. cgitb — Traceback manager for CGI scripts &mdash; Python 3.5.2 documentation</title>
 
10
    
 
11
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
 
12
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
 
13
    
 
14
    <script type="text/javascript">
 
15
      var DOCUMENTATION_OPTIONS = {
 
16
        URL_ROOT:    '../',
 
17
        VERSION:     '3.5.2',
 
18
        COLLAPSE_INDEX: false,
 
19
        FILE_SUFFIX: '.html',
 
20
        HAS_SOURCE:  true
 
21
      };
 
22
    </script>
 
23
    <script type="text/javascript" src="../_static/jquery.js"></script>
 
24
    <script type="text/javascript" src="../_static/underscore.js"></script>
 
25
    <script type="text/javascript" src="../_static/doctools.js"></script>
 
26
    <script type="text/javascript" src="../_static/sidebar.js"></script>
 
27
    <link rel="search" type="application/opensearchdescription+xml"
 
28
          title="Search within Python 3.5.2 documentation"
 
29
          href="../_static/opensearch.xml"/>
 
30
    <link rel="author" title="About these documents" href="../about.html" />
 
31
    <link rel="copyright" title="Copyright" href="../copyright.html" />
 
32
    <link rel="top" title="Python 3.5.2 documentation" href="../contents.html" />
 
33
    <link rel="up" title="21. Internet Protocols and Support" href="internet.html" />
 
34
    <link rel="next" title="21.4. wsgiref — WSGI Utilities and Reference Implementation" href="wsgiref.html" />
 
35
    <link rel="prev" title="21.2. cgi — Common Gateway Interface support" href="cgi.html" />
 
36
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 
37
    
 
38
    <script type="text/javascript" src="../_static/copybutton.js"></script>
 
39
    <script type="text/javascript" src="../_static/version_switch.js"></script>
 
40
    
 
41
    
 
42
 
 
43
 
 
44
  </head>
 
45
  <body role="document">  
 
46
    <div class="related" role="navigation" aria-label="related navigation">
 
47
      <h3>Navigation</h3>
 
48
      <ul>
 
49
        <li class="right" style="margin-right: 10px">
 
50
          <a href="../genindex.html" title="General Index"
 
51
             accesskey="I">index</a></li>
 
52
        <li class="right" >
 
53
          <a href="../py-modindex.html" title="Python Module Index"
 
54
             >modules</a> |</li>
 
55
        <li class="right" >
 
56
          <a href="wsgiref.html" title="21.4. wsgiref — WSGI Utilities and Reference Implementation"
 
57
             accesskey="N">next</a> |</li>
 
58
        <li class="right" >
 
59
          <a href="cgi.html" title="21.2. cgi — Common Gateway Interface support"
 
60
             accesskey="P">previous</a> |</li>
 
61
        <li><img src="../_static/py.png" alt=""
 
62
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
63
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
64
        <li>
 
65
          <span class="version_switcher_placeholder">3.5.2</span>
 
66
          <a href="../index.html">Documentation </a> &raquo;
 
67
        </li>
 
68
 
 
69
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
 
70
          <li class="nav-item nav-item-2"><a href="internet.html" accesskey="U">21. Internet Protocols and Support</a> &raquo;</li>
 
71
    <li class="right">
 
72
        
 
73
 
 
74
    <div class="inline-search" style="display: none" role="search">
 
75
        <form class="inline-search" action="../search.html" method="get">
 
76
          <input placeholder="Quick search" type="text" name="q" />
 
77
          <input type="submit" value="Go" />
 
78
          <input type="hidden" name="check_keywords" value="yes" />
 
79
          <input type="hidden" name="area" value="default" />
 
80
        </form>
 
81
    </div>
 
82
    <script type="text/javascript">$('.inline-search').show(0);</script>
 
83
         |
 
84
    </li>
 
85
 
 
86
      </ul>
 
87
    </div>    
 
88
 
 
89
    <div class="document">
 
90
      <div class="documentwrapper">
 
91
        <div class="bodywrapper">
 
92
          <div class="body" role="main">
 
93
            
 
94
  <div class="section" id="module-cgitb">
 
95
<span id="cgitb-traceback-manager-for-cgi-scripts"></span><h1>21.3. <a class="reference internal" href="#module-cgitb" title="cgitb: Configurable traceback handler for CGI scripts."><code class="xref py py-mod docutils literal"><span class="pre">cgitb</span></code></a> &#8212; Traceback manager for CGI scripts<a class="headerlink" href="#module-cgitb" title="Permalink to this headline">¶</a></h1>
 
96
<p><strong>Source code:</strong> <a class="reference external" href="https://hg.python.org/cpython/file/3.5/Lib/cgitb.py">Lib/cgitb.py</a></p>
 
97
<hr class="docutils" id="index-0" />
 
98
<p>The <a class="reference internal" href="#module-cgitb" title="cgitb: Configurable traceback handler for CGI scripts."><code class="xref py py-mod docutils literal"><span class="pre">cgitb</span></code></a> module provides a special exception handler for Python scripts.
 
99
(Its name is a bit misleading.  It was originally designed to display extensive
 
100
traceback information in HTML for CGI scripts.  It was later generalized to also
 
101
display this information in plain text.)  After this module is activated, if an
 
102
uncaught exception occurs, a detailed, formatted report will be displayed.  The
 
103
report includes a traceback showing excerpts of the source code for each level,
 
104
as well as the values of the arguments and local variables to currently running
 
105
functions, to help you debug the problem.  Optionally, you can save this
 
106
information to a file instead of sending it to the browser.</p>
 
107
<p>To enable this feature, simply add this to the top of your CGI script:</p>
 
108
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">cgitb</span>
 
109
<span class="n">cgitb</span><span class="o">.</span><span class="n">enable</span><span class="p">()</span>
 
110
</pre></div>
 
111
</div>
 
112
<p>The options to the <a class="reference internal" href="#cgitb.enable" title="cgitb.enable"><code class="xref py py-func docutils literal"><span class="pre">enable()</span></code></a> function control whether the report is
 
113
displayed in the browser and whether the report is logged to a file for later
 
114
analysis.</p>
 
115
<dl class="function">
 
116
<dt id="cgitb.enable">
 
117
<code class="descclassname">cgitb.</code><code class="descname">enable</code><span class="sig-paren">(</span><em>display=1</em>, <em>logdir=None</em>, <em>context=5</em>, <em>format=&quot;html&quot;</em><span class="sig-paren">)</span><a class="headerlink" href="#cgitb.enable" title="Permalink to this definition">¶</a></dt>
 
118
<dd><p id="index-1">This function causes the <a class="reference internal" href="#module-cgitb" title="cgitb: Configurable traceback handler for CGI scripts."><code class="xref py py-mod docutils literal"><span class="pre">cgitb</span></code></a> module to take over the interpreter&#8217;s
 
119
default handling for exceptions by setting the value of <a class="reference internal" href="sys.html#sys.excepthook" title="sys.excepthook"><code class="xref py py-attr docutils literal"><span class="pre">sys.excepthook</span></code></a>.</p>
 
120
<p>The optional argument <em>display</em> defaults to <code class="docutils literal"><span class="pre">1</span></code> and can be set to <code class="docutils literal"><span class="pre">0</span></code> to
 
121
suppress sending the traceback to the browser. If the argument <em>logdir</em> is
 
122
present, the traceback reports are written to files.  The value of <em>logdir</em>
 
123
should be a directory where these files will be placed. The optional argument
 
124
<em>context</em> is the number of lines of context to display around the current line
 
125
of source code in the traceback; this defaults to <code class="docutils literal"><span class="pre">5</span></code>. If the optional
 
126
argument <em>format</em> is <code class="docutils literal"><span class="pre">&quot;html&quot;</span></code>, the output is formatted as HTML.  Any other
 
127
value forces plain text output.  The default value is <code class="docutils literal"><span class="pre">&quot;html&quot;</span></code>.</p>
 
128
</dd></dl>
 
129
 
 
130
<dl class="function">
 
131
<dt id="cgitb.handler">
 
132
<code class="descclassname">cgitb.</code><code class="descname">handler</code><span class="sig-paren">(</span><em>info=None</em><span class="sig-paren">)</span><a class="headerlink" href="#cgitb.handler" title="Permalink to this definition">¶</a></dt>
 
133
<dd><p>This function handles an exception using the default settings (that is, show a
 
134
report in the browser, but don&#8217;t log to a file). This can be used when you&#8217;ve
 
135
caught an exception and want to report it using <a class="reference internal" href="#module-cgitb" title="cgitb: Configurable traceback handler for CGI scripts."><code class="xref py py-mod docutils literal"><span class="pre">cgitb</span></code></a>.  The optional
 
136
<em>info</em> argument should be a 3-tuple containing an exception type, exception
 
137
value, and traceback object, exactly like the tuple returned by
 
138
<a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></code></a>.  If the <em>info</em> argument is not supplied, the current
 
139
exception is obtained from <a class="reference internal" href="sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></code></a>.</p>
 
140
</dd></dl>
 
141
 
 
142
</div>
 
143
 
 
144
 
 
145
          </div>
 
146
        </div>
 
147
      </div>
 
148
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
 
149
        <div class="sphinxsidebarwrapper">
 
150
  <h4>Previous topic</h4>
 
151
  <p class="topless"><a href="cgi.html"
 
152
                        title="previous chapter">21.2. <code class="docutils literal"><span class="pre">cgi</span></code> &#8212; Common Gateway Interface support</a></p>
 
153
  <h4>Next topic</h4>
 
154
  <p class="topless"><a href="wsgiref.html"
 
155
                        title="next chapter">21.4. <code class="docutils literal"><span class="pre">wsgiref</span></code> &#8212; WSGI Utilities and Reference Implementation</a></p>
 
156
  <div role="note" aria-label="source link">
 
157
    <h3>This Page</h3>
 
158
    <ul class="this-page-menu">
 
159
      <li><a href="../bugs.html">Report a Bug</a></li>
 
160
      <li><a href="../_sources/library/cgitb.txt"
 
161
            rel="nofollow">Show Source</a></li>
 
162
    </ul>
 
163
  </div>
 
164
        </div>
 
165
      </div>
 
166
      <div class="clearer"></div>
 
167
    </div>  
 
168
    <div class="related" role="navigation" aria-label="related navigation">
 
169
      <h3>Navigation</h3>
 
170
      <ul>
 
171
        <li class="right" style="margin-right: 10px">
 
172
          <a href="../genindex.html" title="General Index"
 
173
             >index</a></li>
 
174
        <li class="right" >
 
175
          <a href="../py-modindex.html" title="Python Module Index"
 
176
             >modules</a> |</li>
 
177
        <li class="right" >
 
178
          <a href="wsgiref.html" title="21.4. wsgiref — WSGI Utilities and Reference Implementation"
 
179
             >next</a> |</li>
 
180
        <li class="right" >
 
181
          <a href="cgi.html" title="21.2. cgi — Common Gateway Interface support"
 
182
             >previous</a> |</li>
 
183
        <li><img src="../_static/py.png" alt=""
 
184
                 style="vertical-align: middle; margin-top: -1px"/></li>
 
185
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
 
186
        <li>
 
187
          <span class="version_switcher_placeholder">3.5.2</span>
 
188
          <a href="../index.html">Documentation </a> &raquo;
 
189
        </li>
 
190
 
 
191
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
 
192
          <li class="nav-item nav-item-2"><a href="internet.html" >21. Internet Protocols and Support</a> &raquo;</li>
 
193
    <li class="right">
 
194
        
 
195
 
 
196
    <div class="inline-search" style="display: none" role="search">
 
197
        <form class="inline-search" action="../search.html" method="get">
 
198
          <input placeholder="Quick search" type="text" name="q" />
 
199
          <input type="submit" value="Go" />
 
200
          <input type="hidden" name="check_keywords" value="yes" />
 
201
          <input type="hidden" name="area" value="default" />
 
202
        </form>
 
203
    </div>
 
204
    <script type="text/javascript">$('.inline-search').show(0);</script>
 
205
         |
 
206
    </li>
 
207
 
 
208
      </ul>
 
209
    </div>  
 
210
    <div class="footer">
 
211
    &copy; <a href="../copyright.html">Copyright</a> 2001-2016, Python Software Foundation.
 
212
    <br />
 
213
    The Python Software Foundation is a non-profit corporation.
 
214
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
 
215
    <br />
 
216
    Last updated on Sep 23, 2016.
 
217
    <a href="../bugs.html">Found a bug</a>?
 
218
    <br />
 
219
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
 
220
    </div>
 
221
 
 
222
  </body>
 
223
</html>
 
 
b'\\ No newline at end of file'