Skip to content

Commit 205cd72

Browse files
authored
[PLT-1437] Restore client.headers (#1781)
1 parent d71a290 commit 205cd72

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from collections import defaultdict
1111
from datetime import datetime, timezone
1212
from typing import Any, List, Dict, Union, Optional, overload, Callable
13+
from types import MappingProxyType
1314

1415
from labelbox.schema.search_filters import SearchFilter
1516
import requests
@@ -128,6 +129,10 @@ def _init_connection(self) -> requests.Session:
128129

129130
return connection
130131

132+
@property
133+
def headers(self) -> MappingProxyType:
134+
return self._connection.headers
135+
131136
def _default_headers(self):
132137
return {
133138
'Authorization': 'Bearer %s' % self.api_key,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
3+
from unittest.mock import patch
4+
5+
from labelbox.client import Client
6+
7+
8+
# @patch.dict(os.environ, {'LABELBOX_API_KEY': 'bar'})
9+
def test_headers():
10+
client = Client(api_key="api_key", endpoint="http://localhost:8080/_gql")
11+
assert client.headers
12+
assert client.headers["Authorization"] == "Bearer api_key"
13+
assert client.headers["Content-Type"] == "application/json"
14+
assert client.headers["User-Agent"]
15+
assert client.headers["X-Python-Version"]

0 commit comments

Comments
 (0)