title: Python : Download CSV file from a URL after login authentication
body: <p>I want to download some data as a csv from an Airbnb that requires a login to download. So, I tried:</p>
  <pre><code>import urllib
  import urllib.request
  username = &quot;username&quot;
  password = &quot;password&quot;
  url = 'someurl'
  values = { 'username': username,'password': password }
  data = urllib.parse.urlencode(values).encode(&quot;utf-8&quot;)
  response = urllib.request.urlopen(url, data)
  result = response.read()
  print (result)
  </code></pre>
  <p>I manage to get the API call URL through right click-&gt; Inspect Element -&gt;Network but I got</p>
  <p><code>HTTP Error 403: Forbidden</code>.</p>
  <p>I tried using the requests module too:</p>
  <pre><code>import requests
  username = &quot;username&quot;
  password = &quot;password&quot;
  url = 'someurl'
  print(requests.get(url, auth=(username, password)).content)
  </code></pre>
  <p>But got an error:</p>
  <p><code>b'{&quot;error_code&quot;:401,&quot;error&quot;:&quot;authentication_required&quot;,&quot;error_message&quot;:&quot;Please log in to continue.&quot;}'</code></p>
  <p>Is there any way from which I can extract this data?</p>
  <p>Edit: My Airbnb booking history's search query is the required URL here.</p>