0
我试图从URL下载CSV文件&将它保存到我的硬盘上的文件。我试图在Python 2.7上使用下面的代码,但得到错误。 CSV位于SharePoint网站上。使用Python 2.7从URL下载CSV文件
import urllib
import csv
url = 'https://office.com/sites/20Reporting/Lists/Reports/476%20-%2050%20DaySDShrink%20Report/476-%2030%20DaySDShrink.csv'
csv = urllib.urlopen(url).read() # returns type 'str'
with open('C:\Users\Documents\DPAM.csv', 'wb') as fx:
fx.write(csv)
我收到以下错误消息。
IOError: ('http error', 401, 'Unauthorized', <httplib.HTTPMessage instance at 0x037541E8>)
你得到的错误说明了一切。您无权访问资源。它依赖于服务器,如果它接受任何授权头,你将不得不与请求一起发送。 – Terry
嗯,但如果我手动将网址,我可以访问下载文件。 –