我尝试过requests、pydap、urllib和netcdf4,在尝试下载以下NASA数据时,总是会遇到重定向错误或权限错误:
GLDAS NOAH025SUBP_3H:GLDAS Noah陆地表面模型L4 3每小时0.25 x 0.25度,子集V001(http://disc.sci.gsfc.nasa.gov/uui/datasets/GLDAS_NOAH025SUBP_3H_V001/summary?keywords=Hydrology)
我正在尝试下载大约50k个文件,这里有一个例子,当粘贴到googlechrome浏览器(如果你有正确的用户名和密码)时,它可以工作:
有没有人有使用python从web上获取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示例,它给出了重定向错误:
^{pr2}$
我没有找到使用python的解决方案,但是根据我现在掌握的信息,这应该是可能的。我将wget与.netrc文件和cookie文件一起使用,如下所示(https://disc.gsfc.nasa.gov/information/howto?title=How%20to%20Download%20Data%20Files%20from%20HTTP%20Service%20with%20wget):
希望它能帮助其他人从这个服务器上处理美国宇航局的数据。在
相关问题 更多 >
编程相关推荐