I'm getting an error when asking Gemini with text+files

model:gemini-1.5-flash-latest
file type:mp4

Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/root/Gemini_yhchatbot/main.py", line 234, in push_message
    response = model.generate_content([prompt] + uploaded_files, stream=True) 
  File "/usr/local/lib/python3.10/dist-packages/google/generativeai/generative_models.py", line 325, in generate_content
    iterator = self._client.stream_generate_content(
  File "/usr/local/lib/python3.10/dist-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py", line 1134, in stream_generate_content
    response = rpc(
  File "/usr/local/lib/python3.10/dist-packages/google/api_core/gapic_v1/method.py", line 131, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/google/api_core/retry/retry_unary.py", line 293, in retry_wrapped_func
    return retry_target(
  File "/usr/local/lib/python3.10/dist-packages/google/api_core/retry/retry_unary.py", line 153, in retry_target
    _retry_error_helper(
  File "/usr/local/lib/python3.10/dist-packages/google/api_core/retry/retry_base.py", line 212, in _retry_error_helper
    raise final_exc from source_exc
  File "/usr/local/lib/python3.10/dist-packages/google/api_core/retry/retry_unary.py", line 144, in retry_target
    result = target()
  File "/usr/local/lib/python3.10/dist-packages/google/api_core/timeout.py", line 120, in func_with_timeout
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/google/api_core/grpc_helpers.py", line 174, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.FailedPrecondition: 400 The File 2wgw6av1x6oz is not in an ACTIVE state and usage is not allowed.

Welcome to the forum.

The potential status of a file right after it has been uploaded to the File API is documented here - Using files  |  Gemini API  |  Google AI for Developers

You can pass it as a Part to generate_content only when State is ACTIVE. To ensure that it is, put a loop just before the call to generate_content in which you call get_file and check the State. Keep looping as long as it says it is PROCESSING.

Hope that helps.

1 Like