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

Follow URL redirects and get Cookie from correct provider #18

Merged
merged 1 commit into from
Nov 6, 2023
Merged
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
12 changes: 9 additions & 3 deletions pysuez/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,26 @@ def _get_cookie(self):
'tsme_user_login[_password]': self._password
}
url = BASE_URI+API_ENDPOINT_LOGIN

try:
self._session.post(url,
response = self._session.post(url,
headers=self._headers,
data=data,
allow_redirects=False,
allow_redirects=True,
timeout=self._timeout)
except OSError:
raise PySuezError("Can not submit login form.")

# Get the URL after possible redirect
m = re.match('https?://([^/]+)/',response.url)
self._hostname = m.group(1)

if not 'eZSESSID' in self._session.cookies.get_dict():
raise PySuezError("Login error: Please check your username/password.")

self._headers['Cookie'] = ''
self._headers['Cookie'] = 'eZSESSID='+self._session.cookies.get("eZSESSID")
session_id=self._session.cookies.get(name="eZSESSID",domain=self._hostname)
self._headers['Cookie'] = 'eZSESSID='+session_id
return True


Expand Down