| Server IP : 82.208.35.60 / Your IP : 216.73.216.168 Web Server : Apache/2.4.55 (FreeBSD) OpenSSL/1.1.1q-freebsd PHP/7.3.31 System : FreeBSD server7.d2m.cz 12.4-RELEASE-p9 FreeBSD 12.4-RELEASE-p9 GENERIC amd64 User : studiokobylisy_cz ( 1008) PHP Version : 7.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /usr/local/share/doc/requests-toolbelt/ |
Upload File : |
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Utilities for Dumping Information About Responses — requests_toolbelt 0.8.0 documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'0.8.0',
LANGUAGE:'None',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Utilities for Enhanced Form-Data Serialization" href="formdata.html" />
<link rel="prev" title="Utilities for Downloading Streaming Responses" href="downloadutils.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> requests_toolbelt
</a>
<div class="version">
0.8.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="user.html">requests toolbelt</a></li>
<li class="toctree-l1"><a class="reference internal" href="contributing.html">Contributing to this project</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="adapters.html">Transport Adapters</a></li>
<li class="toctree-l1"><a class="reference internal" href="authentication.html">Authentication</a></li>
<li class="toctree-l1"><a class="reference internal" href="deprecated.html">Deprecated Requests Utilities</a></li>
<li class="toctree-l1"><a class="reference internal" href="downloadutils.html">Utilities for Downloading Streaming Responses</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Utilities for Dumping Information About Responses</a></li>
<li class="toctree-l1"><a class="reference internal" href="formdata.html">Utilities for Enhanced Form-Data Serialization</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptions.html">Custom Toolbelt Exceptions</a></li>
<li class="toctree-l1"><a class="reference internal" href="sessions.html">Specialized Sessions</a></li>
<li class="toctree-l1"><a class="reference internal" href="threading.html">Using requests with Threading</a></li>
<li class="toctree-l1"><a class="reference internal" href="uploading-data.html">Uploading Data</a></li>
<li class="toctree-l1"><a class="reference internal" href="user-agent.html">User-Agent Constructor</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">requests_toolbelt</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Utilities for Dumping Information About Responses</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/dumputils.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="utilities-for-dumping-information-about-responses">
<span id="dumputils"></span><h1>Utilities for Dumping Information About Responses<a class="headerlink" href="#utilities-for-dumping-information-about-responses" title="Permalink to this headline">¶</a></h1>
<p>Occasionally, it is helpful to know almost exactly what data was sent to a
server and what data was received. It can also be challenging at times to
gather all of that data from requests because of all of the different places
you may need to look to find it. In <code class="xref py py-mod docutils literal"><span class="pre">requests_toolbelt.utils.dump</span></code> there
are two functions that will return a <code class="xref py py-class docutils literal"><span class="pre">bytearray</span></code> with the information
retrieved from a response object.</p>
<dl class="function">
<dt id="requests_toolbelt.utils.dump.dump_all">
<code class="descclassname">requests_toolbelt.utils.dump.</code><code class="descname">dump_all</code><span class="sig-paren">(</span><em>response</em>, <em>request_prefix=b'< '</em>, <em>response_prefix=b'> '</em><span class="sig-paren">)</span><a class="headerlink" href="#requests_toolbelt.utils.dump.dump_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Dump all requests and responses including redirects.</p>
<p>This takes the response returned by requests and will dump all
request-response pairs in the redirect history in order followed by the
final request-response.</p>
<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
<span class="kn">from</span> <span class="nn">requests_toolbelt.utils</span> <span class="k">import</span> <span class="n">dump</span>
<span class="n">resp</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'https://httpbin.org/redirect/5'</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">dump</span><span class="o">.</span><span class="n">dump_all</span><span class="p">(</span><span class="n">resp</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'utf-8'</span><span class="p">))</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>response</strong> (<code class="xref py py-class docutils literal"><span class="pre">requests.Response</span></code>) – The response to format</li>
<li><strong>request_prefix</strong> (<code class="xref py py-class docutils literal"><span class="pre">bytes</span></code>) – (<em>optional</em>)
Bytes to prefix each line of the request data</li>
<li><strong>response_prefix</strong> (<code class="xref py py-class docutils literal"><span class="pre">bytes</span></code>) – (<em>optional</em>)
Bytes to prefix each line of the response data</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Formatted bytes of request and response information.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><code class="xref py py-class docutils literal"><span class="pre">bytearray</span></code></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="requests_toolbelt.utils.dump.dump_response">
<code class="descclassname">requests_toolbelt.utils.dump.</code><code class="descname">dump_response</code><span class="sig-paren">(</span><em>response</em>, <em>request_prefix=b'< '</em>, <em>response_prefix=b'> '</em>, <em>data_array=None</em><span class="sig-paren">)</span><a class="headerlink" href="#requests_toolbelt.utils.dump.dump_response" title="Permalink to this definition">¶</a></dt>
<dd><p>Dump a single request-response cycle’s information.</p>
<p>This will take a response object and dump only the data that requests can
see for that single request-response cycle.</p>
<p>Example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
<span class="kn">from</span> <span class="nn">requests_toolbelt.utils</span> <span class="k">import</span> <span class="n">dump</span>
<span class="n">resp</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'https://api.github.com/users/sigmavirus24'</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">dump</span><span class="o">.</span><span class="n">dump_response</span><span class="p">(</span><span class="n">resp</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'utf-8'</span><span class="p">))</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>response</strong> (<code class="xref py py-class docutils literal"><span class="pre">requests.Response</span></code>) – The response to format</li>
<li><strong>request_prefix</strong> (<code class="xref py py-class docutils literal"><span class="pre">bytes</span></code>) – (<em>optional</em>)
Bytes to prefix each line of the request data</li>
<li><strong>response_prefix</strong> (<code class="xref py py-class docutils literal"><span class="pre">bytes</span></code>) – (<em>optional</em>)
Bytes to prefix each line of the response data</li>
<li><strong>data_array</strong> (<code class="xref py py-class docutils literal"><span class="pre">bytearray</span></code>) – (<em>optional</em>)
Bytearray to which we append the request-response cycle data</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Formatted bytes of request and response information.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><code class="xref py py-class docutils literal"><span class="pre">bytearray</span></code></p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="formdata.html" class="btn btn-neutral float-right" title="Utilities for Enhanced Form-Data Serialization" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="downloadutils.html" class="btn btn-neutral float-left" title="Utilities for Downloading Streaming Responses" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2015, Ian Cordasco, Cory Benfield
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>