-
Notifications
You must be signed in to change notification settings - Fork 463
Closed
Labels
component:python sdkIssue/PR related to Python SDKIssue/PR related to Python SDKstatus:awaiting user responseAwaiting a response from the authorAwaiting a response from the authortype:questionSupport-related issuesSupport-related issues
Description
Description of the bug:
When I try to upload an image to Gemini, it gives me an error. I am using v0.7.2.
import google.generativeai as genai
genai.configure(api_key=GEMINI_API_KEY)
genai.upload_file("absolutepathto/image.png")
Actual vs expected behavior:
---------------------------------------------------------------------------
_InactiveRpcError Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/google/api_core/grpc_helpers.py:76, in _wrap_unary_errors.<locals>.error_remapped_callable(*args, **kwargs)
75 try:
---> 76 return callable_(*args, **kwargs)
77 except grpc.RpcError as exc:
File /opt/conda/lib/python3.10/site-packages/grpc/_channel.py:1181, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
1175 (
1176 state,
1177 call,
1178 ) = self._blocking(
1179 request, timeout, metadata, credentials, wait_for_ready, compression
1180 )
-> 1181 return _end_unary_response_blocking(state, call, False, None)
File /opt/conda/lib/python3.10/site-packages/grpc/_channel.py:1006, in _end_unary_response_blocking(state, call, with_call, deadline)
1005 else:
-> 1006 raise _InactiveRpcError(state)
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.FAILED_PRECONDITION
details = "Unauthorized: Missing authentication token"
debug_error_string = "UNKNOWN:Error received from peer ipv4:34.128.171.17:443 {created_time:"2024-09-09T13:27:28.392766886+00:00", grpc_status:9, grpc_message:"Unauthorized: Missing authentication token"}"
>
The above exception was the direct cause of the following exception:
FailedPrecondition Traceback (most recent call last)
Cell In[42], line 1
----> 1 genai.upload_file(image_path)
File /opt/conda/lib/python3.10/site-packages/google/generativeai/files.py:71, in upload_file(path, mime_type, name, display_name, resumable)
68 if display_name is None:
69 display_name = path.name
---> 71 response = client.create_file(
72 path=path, mime_type=mime_type, name=name, display_name=display_name, resumable=resumable
73 )
74 return file_types.File(response)
File /opt/conda/lib/python3.10/site-packages/google/generativeai/client.py:97, in FileServiceClient.create_file(self, path, mime_type, name, display_name, resumable)
94 request = self._discovery_api.media().upload(body={"file": file}, media_body=media)
95 result = request.execute()
---> 97 return self.get_file({"name": result["file"]["name"]})
File /opt/conda/lib/python3.10/site-packages/google/ai/generativelanguage_v1beta/services/file_service/client.py:921, in FileServiceClient.get_file(self, request, name, retry, timeout, metadata)
918 self._validate_universe_domain()
920 # Send the request.
--> 921 response = rpc(
922 request,
923 retry=retry,
924 timeout=timeout,
925 metadata=metadata,
926 )
928 # Done; return the response.
929 return response
File /opt/conda/lib/python3.10/site-packages/google/api_core/gapic_v1/method.py:131, in _GapicCallable.__call__(self, timeout, retry, compression, *args, **kwargs)
128 if self._compression is not None:
129 kwargs["compression"] = compression
--> 131 return wrapped_func(*args, **kwargs)
File /opt/conda/lib/python3.10/site-packages/google/api_core/grpc_helpers.py:78, in _wrap_unary_errors.<locals>.error_remapped_callable(*args, **kwargs)
76 return callable_(*args, **kwargs)
77 except grpc.RpcError as exc:
---> 78 raise exceptions.from_grpc_error(exc) from exc
FailedPrecondition: 400 Unauthorized: Missing authentication token
Any other information you'd like to share?
I've confirmed that the API key is correct by running another text-only prompt.
Metadata
Metadata
Assignees
Labels
component:python sdkIssue/PR related to Python SDKIssue/PR related to Python SDKstatus:awaiting user responseAwaiting a response from the authorAwaiting a response from the authortype:questionSupport-related issuesSupport-related issues