title: python - urllib.error.HTTPError: HTTP Error 401: Unauthorized
body: <p>I'm new to pyhton and just tried to write data from external file. I have no idea where i'm going wrong. can anyone please help me with this.
  Thanks in advance.</p>
  
  <pre><code>from urllib import request
  
  url = r'https://query1.finance.yahoo.com/v7/finance/download/AMD?period1=1497317134&amp;period2=1499909134&amp;interval=1d&amp;events=history&amp;crumb=HwDtuBHqtg0'
  
  def download_csv(csv_url):
  
      csv = request.urlopen(csv_url)
      csv_data = csv.read
      csv_str = str(csv_data)
      file = csv_str.split('\\n')
      dest_url = r'appl.csv'
      wr = open(dest_url, 'w')
      for data in file:
          wr.write(data + '\n')
      wr.close()
  
  download_csv(url)
  </code></pre>