Python 在Google Colaboratory上使用NASA数据的请求

Python 在Google Colaboratory上使用NASA数据的请求,python,request,google-colaboratory,Python,Request,Google Colaboratory,我试图使用Request从NASA数据访问下载很多lik,但我得到了错误代码401,可能是因为我无法进行身份验证。事实上,我有一个.netrc文件,其中包含代码machine urs.earthdata.nasa.gov登录密码,但我不知道Google Colaboratory如何识别和运行允许下载文件的.netrc文件 我尝试使用的代码是: URL = rutas_GPM.iloc[i,0] # Set the FILENAME string to the data file

我试图使用Request从NASA数据访问下载很多lik,但我得到了
错误代码401
,可能是因为我无法进行身份验证。事实上,我有一个.netrc文件,其中包含代码
machine urs.earthdata.nasa.gov登录密码
,但我不知道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
cd$HOME
touch.netrc
echo“machine urs.earthdata.nasa.gov登录密码”>>.netrc
chmod 0600.netrc
是您的NASA ID,
是您的密码帐户

此外,您必须将以前在Windows操作系统中创建的.netrc文件上载到PC上的“home”和“root”文件夹(在colab环境中)。然后,运行代码并开始下载这些文件