'Downloading a csv from a url sometimes fails [duplicate]

I used the codes below to extract historical data from nasdaq.com but it failed.

import pandas as pd
link = "https://www.nasdaq.com/api/v1/historical/BFC/stocks/2015-07-12/2020-07-12"
data = pd.read_csv(link, skiprows=2)
print(data)

Then I tried another code below but also failed.

import csv
import requests

csv_url = 'https://www.nasdaq.com/api/v1/historical/BFC/stocks/2015-07-12/2020-07-12/'
req = requests.get(csv_url)
url_content = req.content
csv_file = open('downloaded.csv', 'wb')
csv_file.write(url_content)
csv_file.close()

But the codes above work for some other url links like https://www.ishares.com/de/professionelle-anleger/de/produkte/270048/ishares-msci-world-value-factor-ucits-etf/1478358465952.ajax?fileType=csv&fileName=IS3S_holdings&dataType=fund&asOfDate=20180731

Anyone could advise?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source