HumanSignal / label-studio-sdk

Label Studio SDK
https://api.labelstud.io
Apache License 2.0
99 stars 61 forks source link

Add cookies to Client SDK #76

Closed colby-vickerson closed 1 year ago

colby-vickerson commented 2 years ago

I need to pass cookies to the requests session setup in the Client class. The current functionality only supports headers when instantiating the Client class. Update functionality to also allow cookies to be passed into the requests session.

colby-vickerson commented 2 years ago

When creating the PR, I noticed that you can pass in a session to the Client __init__.
https://github.com/heartexlabs/label-studio-sdk/blob/d6ae9585fc068915a54cd6a6839669b7a4e3f599/label_studio_sdk/client.py#L32.

In the session passed into Client, you can do the following to setup the cookies:

MAX_RETRIES = 3
HEADERS = {}

session = requests.Session()
session.headers.update(HEADERS)
session.cookies.update(cookies)
session.mount('http://', HTTPAdapter(max_retries=MAX_RETRIES))
session.mount('https://', HTTPAdapter(max_retries=MAX_RETRIES))

Client(url, api_key, session=session)

I think the cookies is a nice addition because you can take advantage of this method that sets up the session:

https://github.com/heartexlabs/label-studio-sdk/blob/d6ae9585fc068915a54cd6a6839669b7a4e3f599/label_studio_sdk/client.py#L207

makseq commented 1 year ago

Merged to master.