title: Python Download file with Pandas / Urllib
body: <p>I am trying to download a CSV file with Python 3.x
  The path of the file is: <a href="https://www.nseindia.com/content/fo/fo_mktlots.csv" rel="noreferrer">https://www.nseindia.com/content/fo/fo_mktlots.csv</a></p>
  
  <p>I have found three ways to do it. Of the three only one method works. I wanted to know why or what I am doing wrong.</p>
  
  <ol>
  <li><p>Method 1: (Unsuccessful) </p>
  
  <pre><code>import pandas as pd
  
  mytable = pd.read_table("https://www.nseindia.com/content/fo/fo_mktlots.csv",sep=",")
  print(mytable)
  </code></pre>
  
  <p>But I am getting the following error :</p>
  
  <pre><code>- HTTPError: HTTP Error 403: Forbidden
  </code></pre></li>
  <li><p>Method 2: (Unsuccessful)</p>
  
  <pre><code>from urllib.request import Request, urlopen
  
  url='https://www.nseindia.com/content/fo/fo_mktlots.csv'
  
  url_request  = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
  html = urlopen(url_request ).read()
  </code></pre>
  
  <p>Got the same error as before :</p>
  
  <pre><code> - HTTPError: HTTP Error 403: Forbidden
  </code></pre></li>
  <li><p>Method 3: (Successful)</p>
  
  <pre><code>import requests
  import pandas as pd
  
  url = 'https://www.nseindia.com/content/fo/fo_mktlots.csv'
  
  r = requests.get(url)
  df = pd.read_csv(StringIO(r.text))
  </code></pre></li>
  </ol>
  
  <p>I am also able to open the file with Excel VBA as below:</p>
  
  <pre><code>Workbooks.Open Filename:="https://www.nseindia.com/content/fo/fo_mktlots.csv"
  </code></pre>
  
  <p>Also, is there any other method to do the same?</p>