我尝试过请求、pydap、urllib 和 netcdf4,并且在尝试下载以下 NASA 数据时不断收到重定向错误或权限错误:
GLDAS_NOAH025SUBP_3H:GLDAS 诺亚陆地表面模型 L4 3 小时 0.25 x 0.25 度子集 V001(http://disc.sci.gsfc.nasa.gov/uui/datasets/GLDAS_NOAH025SUBP_3H_V001/summary?keywords=Hydrology)
我正在尝试下载大约 50k 个文件,这是一个示例,它在粘贴到 google chrome 浏览器时有效(如果您有正确的用户名和密码):
有人有使用 python 从网络获取 OPeNDAP NASA 数据的经验吗?如果需要,我很乐意提供更多信息。
这是给出 401 错误的请求尝试:
import requests
def httpdownload():
'''loop through each line in the text file and open url'''
httpfile = open(pathlist[0]+"NASAdownloadSample.txt", "r")
for line in httpfile:
print line
outname = line[-134:-122]+".hdf"
print outname
username = ""
password = "*"
r = requests.get(line, auth=("username", "password"), stream=True)
print r.text
print r.status_code
with open(pathlist[0]+outname, 'wb') as out:
out.write(r.content)
print outname, "finished" # keep track of progress
这是给出重定向错误的pydap示例:
import install_cas_client
from pydap.client import open_url
def httpdownload():
'''loop through each line in the text file and open url'''
username = ""
password = ""
httpfile = open(pathlist[0]+"NASAdownloadSample.txt", "r")
fileone = httpfile.readline()
filetot = fileone[:7]+username+":"+password+"@"+fileone[7:]
print filetot
dataset = open_url(filetot)