Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CertificateError: hostname 'goldsmr4.sci.gsfc.nasa.gov' doesn't match either of
- '*.gesdisc.eosdis.nasa.gov', 'gesdisc.eosdis.nasa.gov'
- def __create_authenticated_sesseion(self):
- s = requests.Session()
- s.headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.85 Safari/537.36'}
- s.auth = (self.__username, self.__password)
- s.cookies = self.__authorize_cookies_with_urllib()
- def __authorize_cookies_with_urllib(self):
- username = self.__username
- password = self.__password
- top_level_url = "https://urs.earthdata.nasa.gov"
- # create an authorization handler
- p = urllib.request.HTTPPasswordMgrWithDefaultRealm()
- p.add_password(None, top_level_url, username, password);
- auth_handler = urllib.request.HTTPBasicAuthHandler(p)
- auth_cookie_jar = cookiejar.CookieJar()
- cookie_jar = urllib.request.HTTPCookieProcessor(auth_cookie_jar)
- opener = urllib.request.build_opener(auth_handler, cookie_jar)
- urllib.request.install_opener(opener)
- def __download_and_save_file(self, url, file_path):
- r = self._authenticated_session.get(url, stream=True)
- with open(file_path, 'wb') as f:
- for chunk in r.iter_content(chunk_size=1024):
- if chunk:
- f.write(chunk)
- return r.status_code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement