Giter Site home page Giter Site logo

Comments (7)

descilla avatar descilla commented on August 24, 2024 1

Hi,
it is important to provide an URL with the proper protocol identifier. While your local installation is plain http the cvat instance in your initial post seems to rely on https only (with a http to https redirect) while you are providing a http-url in your configuration. http://example.com and https://example.com were considered as independent scopes in view of security.

ps:

your second example could be simplified (it is not necessary to retrieve the api key or login explicitly):

# Set up an API client
# Read Configuration class docs for more info about parameters and authentication methods
from pprint import pprint
from cvat_sdk.api_client import Configuration, ApiClient, exceptions
configuration = Configuration(
    host='https://hostname/',
    username="user",
    password="password"
)

with ApiClient(configuration) as api_client:
    cvat_id = 585

    format = 'CVAT for images 1.1'
    try:
        (data, response) = api_client.tasks_api.retrieve_annotations(cvat_id, _parse_response=False)
        pprint(data)
    except exceptions.ApiException as e:
        print("Exception when calling TasksApi.retrieve_annotations(): %s\n" % e)

from cvat.

zhiltsov-max avatar zhiltsov-max commented on August 24, 2024

Hi, please check this function. Consider using the high-level API, if it's possible in your use case.

from cvat.

sagarkalburgi avatar sagarkalburgi commented on August 24, 2024

Hi,

I have tried using the high-level API but, I still get the same error.

from cvat_sdk import Config, Client

config = Config()
# set up some config fields ...

with Client('http://cvat-intern.clkgmbh.de/', config=config) as client:
    client.login(('username', 'password'))

    # Retrieve annotations using the authenticated client
    cvat_id = 585

    try:
        # Fetch annotations for the specified task
        annotations = client.tasks.retrieve(cvat_id)
        pprint(annotations)
    except Exception as e:
        print(f"Exception when calling retrieve_annotations: {e}")
Exception when calling retrieve_annotations: Status Code: 401
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Server': 'nginx', 'Date': 'Tue, 16 Jul 2024 13:27:50 GMT', 'Content-Type': 'application/vnd.cvat+json', 'Content-Length': '58', 'Connection': 'keep-alive', 'Allow': 'GET, PATCH, DELETE, HEAD, OPTIONS', 'Cross-Origin-Opener-Policy': 'same-origin', 'Referrer-Policy': 'same-origin, strict-origin-when-cross-origin', 'Vary': 'Accept, Origin, Cookie', 'Www-Authenticate': 'Token', 'X-Content-Type-Options': 'nosniff, nosniff', 'X-Frame-Options': 'DENY', 'X-Request-Id': '43e5b767-681b-44ec-b036-28da310d1f0c'})
HTTP response body: {"detail":"Authentication credentials were not provided."}

from cvat.

zhiltsov-max avatar zhiltsov-max commented on August 24, 2024

Please try to add an extra header like this:

client.api_client.set_default_header("X-Csrftoken", client.api_client.cookies.get("csrftoken"))

from cvat.

sagarkalburgi avatar sagarkalburgi commented on August 24, 2024

After adding an extra header:

client.api_client.set_default_header("X-Csrftoken", client.api_client.cookies.get("csrftoken"))

I get the following error:
Exception when calling retrieve_annotations: expected string or bytes-like object, got 'dict'

I have also installed a local CVAT version for further debugging. With high-level API:

from cvat_sdk import Config, Client

config = Config()
# set up some config fields ...

with Client('http://localhost:8080/', config=config) as client:
    client.login(('abc', 'abc1234!'))

    # Retrieve annotations using the authenticated client
    cvat_id = 1

    # client.api_client.set_default_header("X-Csrftoken", client.api_client.cookies.get("csrftoken"))

    try:
        # Fetch annotations for the specified task
        annotations = client.tasks.retrieve(cvat_id)
        pprint(annotations)
    except Exception as e:
        print(f"Exception when calling retrieve_annotations: {e}")

I get the following output:
<Task: id=1>

Using the following method:

# Set up an API client
# Read Configuration class docs for more info about parameters and authentication methods
configuration = Configuration(
    host = 'http://localhost:8080/',
    username = 'abc',
    password = 'abc1234!'
)

# Login
with ApiClient(configuration) as api_client:
    login_serializer_ex_request = LoginSerializerExRequest(
        username="abc",
        email="",
        password="abc1234!"
    )

    cvat_id = 1

    try:
        (data, response) = api_client.auth_api.create_login(login_serializer_ex_request)
        pprint(data)
    except exceptions.ApiException as e:
        print("Exception when calling AuthApi.create_login(): %s\n" % e)


    format = 'CVAT for images 1.1'
    try:
        (data, response) = api_client.tasks_api.retrieve_annotations(cvat_id, _parse_response=False)
        pprint(data)
    except exceptions.ApiException as e:
        print("Exception when calling TasksApi.retrieve_annotations(): %s\n" % e)

I get the following output:

{'key': '890deec95b28a82e0b7bd70720ce06723686a412'}
None

from cvat.

zhiltsov-max avatar zhiltsov-max commented on August 24, 2024

@sagarkalburgi,

I get the following error:
Exception when calling retrieve_annotations: expected string or bytes-like object, got 'dict'

It's hard to guess without the stack trace. It seems like the response contained some data, which could not be parsed, probably you should have used the _parse_response=False parameter in the request parameters.

I have also installed a local CVAT version for further debugging. With high-level API: [...]
I get the following output:
<Task: id=1>

Ok, it seems to be working in that test. The comments in the code snippet speak about annotations, but you requested a task, and it was successfully retrieved.

Using the following method: [...]
I get the following output:
{'key': '890deec95b28a82e0b7bd70720ce06723686a412'}
None

I see you got no error for the second request, so it also seems to be working. None was returned for data because of _parse_response=False in the request parameters. If you're using this parameter, you need to check response.data for returned contents.

Overall, it seems like some proxy server / firewall problem with the deployed instance.

from cvat.

sagarkalburgi avatar sagarkalburgi commented on August 24, 2024

@zhiltsov-max and @descilla Authentication issue has been resolved.

from cvat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.