Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. CertificateError: hostname 'goldsmr4.sci.gsfc.nasa.gov' doesn't match either of
  2. '*.gesdisc.eosdis.nasa.gov', 'gesdisc.eosdis.nasa.gov'
  3.  
  4. def __create_authenticated_sesseion(self):
  5. s = requests.Session()
  6. s.headers = {
  7. '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'}
  8. s.auth = (self.__username, self.__password)
  9. s.cookies = self.__authorize_cookies_with_urllib()
  10.  
  11. def __authorize_cookies_with_urllib(self):
  12. username = self.__username
  13. password = self.__password
  14. top_level_url = "https://urs.earthdata.nasa.gov"
  15.  
  16.  
  17. # create an authorization handler
  18. p = urllib.request.HTTPPasswordMgrWithDefaultRealm()
  19. p.add_password(None, top_level_url, username, password);
  20.  
  21. auth_handler = urllib.request.HTTPBasicAuthHandler(p)
  22. auth_cookie_jar = cookiejar.CookieJar()
  23. cookie_jar = urllib.request.HTTPCookieProcessor(auth_cookie_jar)
  24. opener = urllib.request.build_opener(auth_handler, cookie_jar)
  25.  
  26. urllib.request.install_opener(opener)
  27.  
  28. def __download_and_save_file(self, url, file_path):
  29. r = self._authenticated_session.get(url, stream=True)
  30. with open(file_path, 'wb') as f:
  31. for chunk in r.iter_content(chunk_size=1024):
  32. if chunk:
  33. f.write(chunk)
  34. return r.status_code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement