擅长:python、mysql、java
<p>如果.netrc文件存在于主目录中,当未提供auth参数时,python请求将自动检查该文件在给定计算机(主机名)下的凭据</p>
<p>从请求文档<a href="https://2.python-requests.org/en/master/user/authentication/#netrc-authentication" rel="nofollow noreferrer">https://2.python-requests.org/en/master/user/authentication/#netrc-authentication</a></p>
<blockquote>
<p>If no authentication method is given with the auth argument, Requests will attempt to get the authentication credentials for the URL’s hostname from the user’s netrc file. The netrc file overrides raw HTTP authentication headers set with headers=.</p>
</blockquote>
<blockquote>
<p>If credentials for the hostname are found, the request is sent with HTTP Basic Auth.</p>
</blockquote>
<p>假设您的主目录中有一个有效的.netrc文件,则以下操作应该可以正常工作<a href="https://www.labkey.org/Documentation/wiki-page.view?name=netrc" rel="nofollow noreferrer">https://www.labkey.org/Documentation/wiki-page.view?name=netrc</a></p>
<pre><code>login = requests.get(url)
</code></pre>