Skip to content

[PLT-1437] Restore client.headers #1781

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

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

vbrodsky
Copy link
Contributor

@vbrodsky vbrodsky commented Aug 27, 2024

Description

Restored back client.headers that we have lost as a result of transition to Client to use http connection pool

Tested with the following script using qa staging org:

import urllib.request

from PIL import Image

from val_scripts.utils import TestClient

# import logging
# logging.basicConfig()
# logging.getLogger().setLevel(logging.DEBUG)

client = TestClient.stg_client()

# === Create data rows ====
org = client.get_organization()
user = client.get_user()
print("Org ", org.uid)
print("User ", user.uid)

composite_mask_url = "https://api.lb-stage.xyz/api/v1/tasks/cm0csqagl00er07yada9qfsd3/masks/clktt4l0j000d3b6qdu7pttqd/index/1"
mask_url = "https://api.lb-stage.xyz/api/v1/projects/clktt2fbx01gf07170ofxfskl/annotations/clktt4lky000f3b6qwsv6stor/index/1/mask"

def download_image(mask_url, client):

    import pdb; pdb.set_trace()
    req = urllib.request.Request(mask_url, headers=client.headers)

    # Optionally, print the image of the mask
    image = Image.open(urllib.request.urlopen(req))
    image.show()


def export_project(project_id: str, client: TestClient):
    params = {
        "data_row_details": True,
        "metadata_fields": True,
        "attachments": True,
        "project_details": True,
        "performance_details": True,
        "label_details": True,
        "interpolated_frames": True}

    project = client.get_project(project_id)
    export_task = project.export_v2(params=params)

    export_task.wait_till_done()
    if export_task.errors:
        print(export_task.errors)
    export_json = export_task.result
    print(export_json)


# export_project('clktt2fbx01gf07170ofxfskl', client)
download_image(mask_url, client)

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Document change (fix typo or modifying any markdown files, code comments or anything in the examples folder only)

All Submissions

  • Have you followed the guidelines in our Contributing document?
  • Have you provided a description?
  • Are your changes properly formatted?

New Feature Submissions

  • Does your submission pass tests?
  • Have you added thorough tests for your new feature?
  • Have you commented your code, particularly in hard-to-understand areas?
  • Have you added a Docstring?

Changes to Core Features

  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you updated any code comments, as applicable?

@vbrodsky vbrodsky requested a review from a team as a code owner August 27, 2024 20:57
@vbrodsky vbrodsky force-pushed the VB/access_to_client_headers_PLT-1437 branch from 361272a to f3a777f Compare August 27, 2024 21:11
@vbrodsky vbrodsky force-pushed the VB/access_to_client_headers_PLT-1437 branch from f3a777f to d98ddba Compare August 27, 2024 21:29
@vbrodsky vbrodsky merged commit 205cd72 into develop Aug 27, 2024
15 of 25 checks passed
@vbrodsky vbrodsky deleted the VB/access_to_client_headers_PLT-1437 branch August 27, 2024 21:54
vbrodsky added a commit that referenced this pull request Aug 28, 2024
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

Successfully merging this pull request may close these issues.

3 participants