0
我正在尝试使用请求和HTTPBasicAuth从需要用户名/密码的网站检索数据,虽然我尝试按照常见的建议让它起作用,它似乎不能正常工作。使用请求和HTTPBasicAuth从受密码保护的站点检索zip文件
具体而言,我试图从哥伦比亚的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))
现在,碰巧,如果我看看请求的内容,我发现它给了我一个html文件,而不是我想要的.zip文件。喜欢的东西:
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
等。看来我实际上无法自动获得我想要的实际zip文件。我正在使用Python 3.5.2,并且非常感谢您的帮助!
最佳,
马特
你确定目标网页应用程序使用'BasicAuthentication'吗? – Andersson