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

feat: add cookies to requests #168

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion mindsdb_sdk/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'mindsdb_sdk'
__package_name__ = 'mindsdb_sdk'
__version__ = '3.1.6'
__version__ = '3.1.7'
__description__ = "MindsDB Python SDK, provides an SDK to use a remote mindsdb instance"
__email__ = "jorge@mindsdb.com"
__author__ = 'MindsDB Inc'
Expand Down
5 changes: 4 additions & 1 deletion mindsdb_sdk/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def connect(
password: str = None,
api_key: str = None,
is_managed: bool = False,
cookies=None,
headers=None) -> Server:
"""
Create connection to mindsdb server
Expand All @@ -21,6 +22,7 @@ def connect(
:param password: user password to login (for cloud version)
:param api_key: API key to authenticate (for cloud version)
:param is_managed: whether or not the URL points to a managed instance
:param cookies: addtional cookies to send with the connection, optional
:param headers: addtional headers to send with the connection, optional
:return: Server object

Expand Down Expand Up @@ -51,6 +53,7 @@ def connect(
# is local
url = DEFAULT_LOCAL_API_URL

api = RestAPI(url, login, password, api_key, is_managed, headers=headers)
api = RestAPI(url, login, password, api_key, is_managed,
cookies=cookies, headers=headers)

return Server(api)
6 changes: 5 additions & 1 deletion mindsdb_sdk/connectors/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def _raise_for_status(response):


class RestAPI:
def __init__(self, url=None, login=None, password=None, api_key=None, is_managed=False, headers=None):
def __init__(self, url=None, login=None, password=None, api_key=None, is_managed=False,
cookies=None, headers=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what cookie name is going to be used? is it related to authorization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cookies are used to track session. I'll add you the related PRs.


self.url = url
self.username = login
Expand All @@ -46,6 +47,9 @@ def __init__(self, url=None, login=None, password=None, api_key=None, is_managed
self.is_managed = is_managed
self.session = requests.Session()

if cookies is not None:
self.session.cookies.update(cookies)

self.session.headers['User-Agent'] = f'python-sdk/{__about__.__version__}'
if headers is not None:
self.session.headers.update(headers)
Expand Down
Loading