Skip to content
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

Failed to upload a file - FailedPrecondition: 400 Unauthorized: Missing authentication token #542

Closed
tsuga opened this issue Sep 9, 2024 · 6 comments
Assignees
Labels
component:python sdk Issue/PR related to Python SDK status:awaiting user response Awaiting a response from the author type:help Support-related issues

Comments

@tsuga
Copy link

tsuga commented Sep 9, 2024

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.

@Gunand3043 Gunand3043 self-assigned this Sep 9, 2024
@Gunand3043 Gunand3043 added status:triaged Issue/PR triaged to the corresponding sub-team component:python sdk Issue/PR related to Python SDK type:help Support-related issues labels Sep 9, 2024
@Gunand3043
Copy link

Have you tried uploading other files, such as PDFs or audio files?

@tsuga
Copy link
Author

tsuga commented Sep 9, 2024

I tried with a PDF file. Same error for PDF.

@MarkDaoust
Copy link
Collaborator

Are you sure your key is good? This Files notebook works:

https://colab.sandbox.google.com/github/google-gemini/cookbook/blob/main/quickstarts/File_API.ipynb

Is it possible it's picking up on some application-default credentials and getting confused?

@MarkDaoust MarkDaoust added the status:awaiting user response Awaiting a response from the author label Sep 10, 2024
@tsuga
Copy link
Author

tsuga commented Sep 12, 2024

@MarkDaoust Thank you for checking. I've confirm that the key is good.
I am on Kaggle environment.
image

@MarkDaoust
Copy link
Collaborator

MarkDaoust commented Sep 12, 2024

Oh, kaggle! I was just talking to them.

This might be the fix you need: #548
It's in v0.8.1.

Try updating to 0.8.1 and see if that works.
It if doesn't it may be a matter of waiting until Kaggle updates it to 0.8.1, which should be soon, since they were asking me to fix this.

@tsuga
Copy link
Author

tsuga commented Sep 13, 2024

Thanks. I've updated the library to v0.8.1 and it works without error!

@tsuga tsuga closed this as completed Sep 13, 2024
@github-actions github-actions bot removed the status:triaged Issue/PR triaged to the corresponding sub-team label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK status:awaiting user response Awaiting a response from the author type:help Support-related issues
Projects
None yet
Development

No branches or pull requests

3 participants