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

0.0.32 is not the latest version, source code different with github #172

Open
stevezkw1998 opened this issue Dec 23, 2023 · 1 comment
Open

Comments

@stevezkw1998
Copy link

for example, label_studio_sdk.client.py

The position of self.cookies = cookies is different

the code from 0.0.32

class Client(object):
    def __init__(
        self,
        url: str = None,
        api_key: str = None,
        credentials=None,
        session=None,
        extra_headers: dict = None,
        cookies: dict = None,
        oidc_token=None,
        versions=None,
        make_request_raise=True,
    ):
        """Initialize the client. Do this before using other Label Studio SDK classes and methods in your script.

        Parameters
        ----------
        url: str
            Label Studio host address.
            Example: http://localhost:8080
        api_key: str
            User token for the API. You can find this on your user account page in Label Studio.
        credentials: ClientCredentials
            User email and password or api_key.
        session: requests.Session()
            If None, a new one is created.
        extra_headers: dict
            Additional headers that will be passed to each http request
        cookies: dict
            Cookies that will be passed to each http request.
        oidc_token: str
            Bearer token for proxy authentication - in case the server is behind an authenticating proxy.
        versions: dict
            Versions of Label Studio components for the connected instance
        make_request_raise: bool
            If true, make_request will raise exceptions on request errors
        """
        if not url:
            url = os.getenv('LABEL_STUDIO_URL', LABEL_STUDIO_DEFAULT_URL)
        self.url = url.rstrip('/')
        self.make_request_raise = make_request_raise
        self.session = session or self.get_session()

        # set api key or get it using credentials (username and password)
        if api_key is None and credentials is None:
            api_key = os.getenv('LABEL_STUDIO_API_KEY')

        if api_key is not None:
            credentials = ClientCredentials(api_key=api_key)
        self.api_key = (
            credentials.api_key
            if credentials.api_key
            else self.get_api_key(credentials)
        )

        # set headers
        self.headers = {'Authorization': f'Token {self.api_key}'}
        if oidc_token:
            self.headers.update({'Proxy-Authorization': f'Bearer {oidc_token}'})
        if extra_headers:
            self.headers.update(extra_headers)

        # set cookies
        self.cookies = cookies

        # set versions from /version endpoint
        self.versions = versions if versions else self.get_versions()
        self.is_enterprise = 'label-studio-enterprise-backend' in self.versions

This code from github master branch

class Client(object):
    def __init__(
        self,
        url: str = None,
        api_key: str = None,
        credentials=None,
        session=None,
        extra_headers: dict = None,
        cookies: dict = None,
        oidc_token=None,
        versions=None,
        make_request_raise=True,
    ):
        """Initialize the client. Do this before using other Label Studio SDK classes and methods in your script.

        Parameters
        ----------
        url: str
            Label Studio host address.
            Example: http://localhost:8080
        api_key: str
            User token for the API. You can find this on your user account page in Label Studio.
        credentials: ClientCredentials
            User email and password or api_key.
        session: requests.Session()
            If None, a new one is created.
        extra_headers: dict
            Additional headers that will be passed to each http request
        cookies: dict
            Cookies that will be passed to each http request.
        oidc_token: str
            Bearer token for proxy authentication - in case the server is behind an authenticating proxy.
        versions: dict
            Versions of Label Studio components for the connected instance
        make_request_raise: bool
            If true, make_request will raise exceptions on request errors
        """
        if not url:
            url = os.getenv('LABEL_STUDIO_URL', LABEL_STUDIO_DEFAULT_URL)
        self.url = url.rstrip('/')
        self.make_request_raise = make_request_raise
        self.session = session or self.get_session()

        # set cookies
        self.cookies = cookies

        # set api key or get it using credentials (username and password)
        if api_key is None and credentials is None:
            api_key = os.getenv('LABEL_STUDIO_API_KEY')

        if api_key is not None:
            credentials = ClientCredentials(api_key=api_key)
        self.api_key = (
            credentials.api_key
            if credentials.api_key
            else self.get_api_key(credentials)
        )

        # set headers
        self.headers = {'Authorization': f'Token {self.api_key}'}
        if oidc_token:
            self.headers.update({'Proxy-Authorization': f'Bearer {oidc_token}'})
        if extra_headers:
            self.headers.update(extra_headers)

        # set versions from /version endpoint
        self.versions = versions if versions else self.get_versions()
        self.is_enterprise = 'label-studio-enterprise-backend' in self.versions

When will the latest version be released?
0.0.32 has bugs!

@alexeckert
Copy link

Ran into the same issue, .32 has a bug where you can't use credentials without api key since the cookies field is accessed before it is instantiated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants