How to access a .txt file at a secured url?
<p>I want to read a file from a secured url.</p>

<p>For example: <a href="https://foo.net/test.txt" rel="nofollow">https://foo.net/test.txt</a></p>

<p>when I use: </p>

<pre><code>readtext = urllib.urlopen('https://foo.net/test.txt').read()
</code></pre>

<p>I get a request for username and password. After entering them I can read the file. Is there a way to hardcode the username and password ?</p>

<p>I'm sure it's almost as trivial to do in urllib as it is in requests, but requests is just so darn pretty:</p>

<pre><code>import requests
from requests.auth import HTTPBasicAuth

r = requests.get('https://foo.net/test.txt', auth=HTTPBasicAuth('user', 'pass'))
</code></pre>

python