简体   繁体   English

使用请求和HTTPBasicAuth从受密码保护的站点检索zip文件

[英]Using requests and HTTPBasicAuth to retrieve a zip file from a password-protected site

I am trying to use requests and HTTPBasicAuth to retrieve data from a website that requires a username/password, and while I have tried to follow the usual advice in getting this to work, it doesn't seem to be functioning correctly. 我正在尝试使用请求和HTTPBasicAuth从需要用户名/密码的网站中检索数据,尽管我尝试遵循通常的建议以使其正常工作,但它似乎无法正常运行。

Specifically, I am trying to download data from Columbia's SEDAC website as follows. 具体来说,我正尝试从哥伦比亚的SEDAC网站下载数据,如下所示。

url = "http://sedac.ciesin.columbia.edu/downloads/data/sdei/sdei-global-nnual-avg-pm2-5-modis-misr-seawifs-aod-1998-2012/global-annual-avg-pm2-5-modis-misr-seawifs-aod-2001-2010-geotiff.zip"
username = '<name>'
password = '<password>'
r = requests.get(url, auth=HttpBasicAuth(username, password))

Now, as it happens, if I look at the content of the request, I find that it gives me an html file, not the .zip file that I desire. 现在,碰巧的是,如果我查看请求的内容,我发现它给了我一个html文件,而不是我想要的.zip文件。 Something like: 就像是:

r.content 内容

b'<!DOCTYPE html>\n<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->\n<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"> <![endif]-->\n<!--[if IE 8]><html class="no-js lt-ie9"> <![endif]-->\n<!--[if gt IE 8]><!--><html lang="en" class="no-js"><!--<![endif]-->\n  <head>\n    <meta charset="utf-8">\n    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\n    <title>Earthdata Login</title>\n

and so on. 等等。 It seems that I can't actually automate the getting of the actual zip file I desire. 看来我实际上无法自动获得所需的实际zip文件。 I am using Python 3.5.2 and would be much obliged for any help! 我正在使用Python 3.5.2,将非常有帮助!

Best, 最好,

Matt 马特

The url you are trying to access is not protected by http basic auth. 您尝试访问的网址不受http basic auth的保护。 You need to submit the form with the credentials. 您需要提交带有凭据的表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM