Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update earthexplorer.py #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions landsatxplore/earthexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@
def _get_tokens(body):
"""Get `csrf_token` and `__ncforminfo`."""
csrf = re.findall(r'name="csrf" value="(.+?)"', body)[0]
ncform = re.findall(r'name="__ncforminfo" value="(.+?)"', body)[0]

if not csrf:
raise EarthExplorerError("EE: login failed (csrf token not found).")
if not ncform:
raise EarthExplorerError("EE: login failed (ncforminfo not found).")

return csrf, ncform
return csrf


class EarthExplorer(object):
Expand All @@ -63,12 +60,11 @@ def logged_in(self):
def login(self, username, password):
"""Login to Earth Explorer."""
rsp = self.session.get(EE_LOGIN_URL)
csrf, ncform = _get_tokens(rsp.text)
csrf= _get_tokens(rsp.text)
payload = {
"username": username,
"password": password,
"csrf": csrf,
"__ncforminfo": ncform,
"csrf": csrf
}
rsp = self.session.post(EE_LOGIN_URL, data=payload, allow_redirects=True)

Expand Down