Comments (10)
Okay I fixed it... somehow. Basically, I just switched to a different computer, did the exact same thing, and it worked first try. I suppose that means it was something wrong with the python version or the pip install? I'm not really sure, but I'm not going to stress too hard about it. Thank you for your help.
The situation I encountered is similar to yours. I encountered the same error when using virtualenv, but when I switched to pyenv with the same code, it worked fine. In addition, you don't even need to install Google Cloud CLI since you have the API key. Thank you for your inspiration.
from generative-ai-python.
Can you just stick with the API key and ignore the ADCs? API key is the easiest approach if you can use it.
If you must use ADCs, you can use gcloud
to add the scopes you need (but it'd be helpful for us if you could reply with some info on why API key isn't sufficient):
gcloud auth application-default login --scopes="https://www.googleapis.com/auth/generative-language,https://www.googleapis.com/auth/cloud-platform"
But don't mix the two - either use API key to auth (and remove the environmental references to the ADCs) or use the ADCs (and don't set api_key=...
)
There's some more detail in this comment.
from generative-ai-python.
Okay I tried not setting ADCs, just using an API key. I followed the documentation letter for letter. My API key works perfectly when I run the following curl script:
curl -H 'Content-Type: application/json'
-d '{"prompt": {text: "Give me five subcategories of jazz"} }'
"https://generativelanguage.googleapis.com/v1beta2/models/text-bison-001:generateText?key=${XXXXXXXXXXXXXX}"
but when I run this code (straight from the documentation):
import google.generativeai as palm
import os
os.environ['API_KEY'] = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
palm.configure(api_key=os.environ['API_KEY'])
response = palm.generate_text(prompt="The opposite of hot is")
print(response.result) # 'cold.'
I still get that same error message about token scopes. What should I try? Thank you!
from generative-ai-python.
Also, I tried adding the scopes that you linked in the ADC gcloud code to the project with oauth, but it said they were not valid. I don't know if I am doing something wrong there or what but yeah.
from generative-ai-python.
The client libraries try to use the ADCs up if they are present in the environment - they don't have to be explicitly set. You can remove them using gcloud (log out), delete the files, or just pop the environment var:
import os
# Hide ADCs from Google's API client library
os.environ.pop('GOOGLE_APPLICATION_CREDENTIALS', None)
Maybe there's something we can do better here to avoid the ADCs if an API key is set - I'll leave this open as a FR to "don't use ADCs if an API key is specified".
from generative-ai-python.
Used this code and it still did not work, so I started fresh with a new project. Just used API key, no ADC stuff. Same story, the API key worked with the curl function but I still got the same error when I ran the code. Seems like I've tried everything here so I'm not sure where to go next. Thanks anyways.
from generative-ai-python.
Okay I fixed it... somehow. Basically, I just switched to a different computer, did the exact same thing, and it worked first try. I suppose that means it was something wrong with the python version or the pip install? I'm not really sure, but I'm not going to stress too hard about it. Thank you for your help.
from generative-ai-python.
I think some of the misunderstanding is because GOOGLE_APPLICATION_CREDENTIALS
aren't always necessary.
When I've used ADC with the client libraries I've never set GOOGLE_APPLICATION_CREDENTIALS
, but I did have to set it when trying to use the Node.js client libraries.
gcloud auth application-default login
is probably putting the file in a standard location, and the client library is picking it up from there. So I think it's normal that the env-var makes no difference.
But trying it out:
- It's easy to trigger the
403 Request had insufficient authentication scopes.
error. - But if I pass an API-key, that takes precedence, and it works fine.
So I think this is working fine.
From @hankp46's #51 he said he fixed the same error by pinning the versions of a bunch of the required libraries.
I think that's a clue.
API-KEY support is somewhat new, and and it's possible older versions of one of the helpers libs is causing the problem. Since pip is conservative about upgrading packages, you probably had an old version installed, and pip just kept that? That would explain @zongsforce's observations as well since pyenv installs a whole new python, it would have picked up new versions of the packages?
The culprit package is not google-auth
, 1.24 fails hard on some other error (too old) and 1.25 passes.
@vayvaychicken @zongsforce : Can either of you post the output of pip freeze
from an environment where it's failing like this?
from generative-ai-python.
When I run the app in my local using the API Key, it works perfectly well. But when I run it using github, I got this error: 403 Request had insufficient authentication scopes.
from generative-ai-python.
Hi, I didn't change anything to fix this, but API-keys are rellatively new in google APIs.
I remember when it used to fail like this, but it isn't for me now. Maybe this was fixed lower in the stack.
Do you still have this problem?
from generative-ai-python.
Related Issues (20)
- Gemini version 0.5.* generate_content doesn't provide usageMetadata if stream=True HOT 2
- response.text quick accessor bug HOT 1
- Uri parameter cannot be overridden when sending via rest transport HOT 3
- Clarify google-ai-generativelanguage version HOT 5
- pip install --upgrade google.generativeai => Mac OS malware warning re rustc HOT 4
- File uploads are broken (ValueError: Unknown field for File: state) HOT 2
- `count_tokens` should allow empty content HOT 2
- Is upload_file thread safe? HOT 13
- System Instructions for Gemini 1.0? HOT 5
- stream=True returns all chunks at the same time [in Colab] HOT 2
- A plain text version of gemini 1.5 HOT 2
- Support for Video (MP4) with Gemini Pro 1.5 HOT 11
- Add client timeout setting to overcome timeout errors. HOT 4
- RECITATION error when transcribe audio to text HOT 2
- response_schema parameter is not followed. HOT 2
- google.api_core.exceptions.Unknown: None Stream removed
- Content has no parts HOT 2
- stop_resaon is alwasy STOP, and usage_meta is consistently empty HOT 1
- BlockedPromptException: block_reason: OTHER HOT 1
- chat_session.send_message throw exception while using proxy config: raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='generativelanguage.googleapis.com', port=443) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from generative-ai-python.