from glob import glob
from twelvelabs.models.task import Task
video_files = glob(YOUR_VIDEO_PATH) # Example: "/videos/*.mp4
for video_file in video_files:
print(f"Uploading {video_file}")
task = client.task.create(index_id=YOUR_INDEX_ID, file=video_file, language="en")
print(f"Task id={task.id}")
# (Optional) Monitor the video indexing process
# Utility function to print the status of a video indexing task
def on_task_update(task: Task):
print(f" Status={task.status}")
task.wait_for_done(callback=on_task_update)
if task.status != "ready":
raise RuntimeError(f"Indexing failed with status {task.status}")
print(f"Uploaded {video_file}. The unique identifer of your video is {task.video_id}.")
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py:216, in ConnectionPool.handle_request(self, request)
215 self._close_connections(closing)
--> 216 raise exc from None
218 # Return the response. Note that in this case we still have to manage
219 # the point at which the response is closed.
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py:196, in ConnectionPool.handle_request(self, request)
194 try:
195 # Send the request on the assigned connection.
--> 196 response = connection.handle_request(
197 pool_request.request
198 )
199 except ConnectionNotAvailable:
200 # In some cases a connection may initially be available to
201 # handle a request, but then become unavailable.
202 #
203 # In this case we clear the connection and try again.
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/http11.py:95, in HTTP11Connection.handle_request(self, request)
94 with Trace("send_request_body", logger, request, kwargs) as trace:
---> 95 self._send_request_body(**kwargs)
96 except WriteError:
97 # If we get a write error while we're writing the request,
98 # then we supress this error and move on to attempting to
99 # read the response. Servers can sometimes close the request
100 # pre-emptively and then respond with a well formed HTTP
101 # error response.
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/http11.py:173, in HTTP11Connection._send_event(self, event, timeout)
170 def _send_event(
171 self, event: h11.Event, timeout: Optional[float] = None
172 ) -> None:
--> 173 bytes_to_send = self._h11_state.send(event)
174 if bytes_to_send is not None:
File ~/notebook-env/lib/python3.11/site-packages/h11/_connection.py:512, in Connection.send(self, event)
492 """Convert a high-level event into bytes that can be sent to the peer,
493 while updating our internal state machine.
494
(...)
510
511 """
--> 512 data_list = self.send_with_data_passthrough(event)
513 if data_list is None:
File ~/notebook-env/lib/python3.11/site-packages/h11/_writers.py:65, in BodyWriter.call(self, event, write)
64 if type(event) is Data:
---> 65 self.send_data(event.data, write)
66 elif type(event) is EndOfMessage:
File ~/notebook-env/lib/python3.11/site-packages/h11/_writers.py:91, in ContentLengthWriter.send_data(self, data, write)
90 if self._length < 0:
---> 91 raise LocalProtocolError("Too much data for declared Content-Length")
92 write(data)
LocalProtocolError: Too much data for declared Content-Length
During handling of the above exception, another exception occurred:
UnboundLocalError Traceback (most recent call last)
Cell In[14], line 7
5 for video_file in video_files:
6 print(f"Uploading {video_file}")
----> 7 task = client.task.create(index_id=YOUR_INDEX_ID, file=video_file, language="en")
8 print(f"Task id={task.id}")
10 # (Optional) Monitor the video indexing process
11 # Utility function to print the status of a video indexing task
Sorry for the late reply. We can't fully understand the issue from your report, so we would appreciate it if you could report it based on the issue template.
Uploading ./Testing Groq on Athena.mp4
LocalProtocolError Traceback (most recent call last) File ~/notebook-env/lib/python3.11/site-packages/twelvelabs/base_client.py:29, in APIClient._request(self, method, url, kwargs) 28 try: ---> 29 response = self._client.request(method, url, kwargs) 30 except httpx.TimeoutException as e:
File ~/notebook-env/lib/python3.11/site-packages/httpx/_client.py:827, in request(self, method, url, content, data, files, json, params, headers, cookies, auth, follow_redirects, timeout, extensions) 814 return self.send(request, auth=auth, follow_redirects=follow_redirects) 816 @contextmanager 817 def stream( 818 self, 819 method: str, 820 url: URLTypes, 821 *, 822 content: typing.Optional[RequestContent] = None, 823 data: typing.Optional[RequestData] = None, 824 files: typing.Optional[RequestFiles] = None, 825 json: typing.Optional[typing.Any] = None, 826 params: typing.Optional[QueryParamTypes] = None, --> 827 headers: typing.Optional[HeaderTypes] = None, 828 cookies: typing.Optional[CookieTypes] = None, 829 auth: typing.Union[AuthTypes, UseClientDefault, None] = USE_CLIENT_DEFAULT, 830 follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, 831 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, 832 extensions: typing.Optional[RequestExtensions] = None, 833 ) -> typing.Iterator[Response]: 834 """ 835 Alternative to
httpx.request()
that streams the response body 836 instead of loading it into memory at once. (...) 842 [0]: /quickstart#streaming-responses 843 """File ~/notebook-env/lib/python3.11/site-packages/httpx/_client.py:914, in send(self, request, stream, auth, follow_redirects) 913 except BaseException as exc: --> 914 response.close() 915 raise exc
File ~/notebook-env/lib/python3.11/site-packages/httpx/_client.py:942, in _send_handling_auth(self, request, auth, follow_redirects, history) 941 response.read() --> 942 request = next_request 943 history.append(response)
File ~/notebook-env/lib/python3.11/site-packages/httpx/_client.py:979, in _send_handling_redirects(self, request, follow_redirects, history) 978 if follow_redirects: --> 979 response.read() 980 else:
File ~/notebook-env/lib/python3.11/site-packages/httpx/_client.py:1015, in _send_single_request(self, request) 1011 response.default_encoding = self._default_encoding 1013 logger.info( 1014 'HTTP Request: %s %s "%s %d %s"', -> 1015 request.method, 1016 request.url, 1017 response.http_version, 1018 response.status_code, 1019 response.reason_phrase, 1020 ) 1022 return response
File ~/notebook-env/lib/python3.11/site-packages/httpx/_transports/default.py:233, in handle_request(self, request) 230 assert isinstance(resp.stream, typing.Iterable) 232 return Response( --> 233 status_code=resp.status, 234 headers=resp.headers, 235 stream=ResponseStream(resp.stream), 236 extensions=resp.extensions, 237 )
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py:216, in ConnectionPool.handle_request(self, request) 215 self._close_connections(closing) --> 216 raise exc from None 218 # Return the response. Note that in this case we still have to manage 219 # the point at which the response is closed.
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py:196, in ConnectionPool.handle_request(self, request) 194 try: 195 # Send the request on the assigned connection. --> 196 response = connection.handle_request( 197 pool_request.request 198 ) 199 except ConnectionNotAvailable: 200 # In some cases a connection may initially be available to 201 # handle a request, but then become unavailable. 202 # 203 # In this case we clear the connection and try again.
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/connection.py:101, in HTTPConnection.handle_request(self, request) 99 raise exc --> 101 return self._connection.handle_request(request)
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/http11.py:143, in HTTP11Connection.handle_request(self, request) 142 self._response_closed() --> 143 raise exc
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/http11.py:95, in HTTP11Connection.handle_request(self, request) 94 with Trace("send_request_body", logger, request, kwargs) as trace: ---> 95 self._send_request_body(**kwargs) 96 except WriteError: 97 # If we get a write error while we're writing the request, 98 # then we supress this error and move on to attempting to 99 # read the response. Servers can sometimes close the request 100 # pre-emptively and then respond with a well formed HTTP 101 # error response.
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/http11.py:166, in HTTP11Connection._send_request_body(self, request) 165 event = h11.Data(data=chunk) --> 166 self._send_event(event, timeout=timeout) 168 self._send_event(h11.EndOfMessage(), timeout=timeout)
File ~/notebook-env/lib/python3.11/site-packages/httpcore/_sync/http11.py:173, in HTTP11Connection._send_event(self, event, timeout) 170 def _send_event( 171 self, event: h11.Event, timeout: Optional[float] = None 172 ) -> None: --> 173 bytes_to_send = self._h11_state.send(event) 174 if bytes_to_send is not None:
File ~/notebook-env/lib/python3.11/site-packages/h11/_connection.py:512, in Connection.send(self, event) 492 """Convert a high-level event into bytes that can be sent to the peer, 493 while updating our internal state machine. 494 (...) 510 511 """ --> 512 data_list = self.send_with_data_passthrough(event) 513 if data_list is None:
File ~/notebook-env/lib/python3.11/site-packages/h11/_connection.py:545, in Connection.send_with_data_passthrough(self, event) 544 data_list: List[bytes] = [] --> 545 writer(event, data_list.append) 546 return data_list
File ~/notebook-env/lib/python3.11/site-packages/h11/_writers.py:65, in BodyWriter.call(self, event, write) 64 if type(event) is Data: ---> 65 self.send_data(event.data, write) 66 elif type(event) is EndOfMessage:
File ~/notebook-env/lib/python3.11/site-packages/h11/_writers.py:91, in ContentLengthWriter.send_data(self, data, write) 90 if self._length < 0: ---> 91 raise LocalProtocolError("Too much data for declared Content-Length") 92 write(data)
LocalProtocolError: Too much data for declared Content-Length
During handling of the above exception, another exception occurred:
UnboundLocalError Traceback (most recent call last) Cell In[14], line 7 5 for video_file in video_files: 6 print(f"Uploading {video_file}") ----> 7 task = client.task.create(index_id=YOUR_INDEX_ID, file=video_file, language="en") 8 print(f"Task id={task.id}") 10 # (Optional) Monitor the video indexing process 11 # Utility function to print the status of a video indexing task
File ~/notebook-env/lib/python3.11/site-packages/twelvelabs/resources/task.py:138, in Task.create(self, index_id, file, url, transcription_file, transcription_url, language, disable_video_stream, kwargs) 135 data["provide_transcription"] = True 137 try: --> 138 res = self._post( 139 "tasks", data=remove_none_values(data), files=files, kwargs 140 ) 141 return self.retrieve(res["_id"]) 142 finally:
File ~/notebook-env/lib/python3.11/site-packages/twelvelabs/base_client.py:97, in APIClient.post(self, url, data, json, kwargs) 90 def post( 91 self, 92 url: str, (...) 95 kwargs, 96 ) -> Any: ---> 97 return self._request("POST", url, data=data, json=json, **kwargs)
File ~/notebook-env/lib/python3.11/site-packages/twelvelabs/base_client.py:33, in APIClient._request(self, method, url, **kwargs) 31 raise APITimeoutError(request=response._request) 32 except Exception as e: ---> 33 raise exceptions.APIConnectionError(request=response._request) 35 try: 36 response.raise_for_status()
UnboundLocalError: cannot access local variable 'response' where it is not associated with a value