在 Google Colaboratory 上对 NASA 数据使用 Request
Use Request with NASA data on Google Colaboratory
我正在尝试使用 Request 从 NASA Data Access 下载很多 liks,但我得到 error code 401
,可能是因为我无法进行身份验证。实际上,我有一个包含代码 machine urs.earthdata.nasa.gov login <uid> password <password>
的 .netrc 文件,但我不知道 Google Colaboratory 如何识别和 运行 允许下载文件的 .netrc 文件。
我尝试使用的代码是:
URL = rutas_GPM.iloc[i,0]
# Set the FILENAME string to the data file name, the LABEL keyword value, or any customized name.
FILENAME = 'GPM{0}.nc'.format(i)
result = requests.get(URL)
try:
result.raise_for_status()
f = open("/content/drive/MyDrive/Colab Notebooks/Prueba/"+FILENAME,'wb')
f.write(result.content)
f.close()
print('contents of URL written to '+FILENAME)
except:
print('requests.get() returned an error code '+str(result.status_code))
你能帮我解决这个问题吗?
谢谢
Google Colaboratory 使用基于 Linux 的虚拟环境,在此顺序中,您必须遵循 NASA 为 MAC/Linux 提供的说明:
cd $HOME
touch .netrc
echo "machine urs.earthdata.nasa.gov login <uid> password <password>" >> .netrc
chmod 0600 .netrc
<uid>
是您的 NASA ID,<password>
是您的密码帐户。
此外,您必须将您之前在 Windows OS 中创建的 .netrc 文件上传到“home”和“root”文件夹(在 colab 环境中),个人电脑。然后,您 运行 代码并开始下载文件。
我正在尝试使用 Request 从 NASA Data Access 下载很多 liks,但我得到 error code 401
,可能是因为我无法进行身份验证。实际上,我有一个包含代码 machine urs.earthdata.nasa.gov login <uid> password <password>
的 .netrc 文件,但我不知道 Google Colaboratory 如何识别和 运行 允许下载文件的 .netrc 文件。
我尝试使用的代码是:
URL = rutas_GPM.iloc[i,0]
# Set the FILENAME string to the data file name, the LABEL keyword value, or any customized name.
FILENAME = 'GPM{0}.nc'.format(i)
result = requests.get(URL)
try:
result.raise_for_status()
f = open("/content/drive/MyDrive/Colab Notebooks/Prueba/"+FILENAME,'wb')
f.write(result.content)
f.close()
print('contents of URL written to '+FILENAME)
except:
print('requests.get() returned an error code '+str(result.status_code))
你能帮我解决这个问题吗?
谢谢
Google Colaboratory 使用基于 Linux 的虚拟环境,在此顺序中,您必须遵循 NASA 为 MAC/Linux 提供的说明:
cd $HOME
touch .netrc
echo "machine urs.earthdata.nasa.gov login <uid> password <password>" >> .netrc
chmod 0600 .netrc
<uid>
是您的 NASA ID,<password>
是您的密码帐户。
此外,您必须将您之前在 Windows OS 中创建的 .netrc 文件上传到“home”和“root”文件夹(在 colab 环境中),个人电脑。然后,您 运行 代码并开始下载文件。