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 retrieve data. HTTP Status: 403 #64

Open
Tbma1 opened this issue Apr 14, 2024 · 2 comments
Open

Failed to retrieve data. HTTP Status: 403 #64

Tbma1 opened this issue Apr 14, 2024 · 2 comments
Labels
status:awaiting response Awaiting a response from the author

Comments

@Tbma1
Copy link

Tbma1 commented Apr 14, 2024

import requests
import json

google_api_key = 'my api key'

url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=' + google_api_key

data = {
"contents": [{
"parts": [{
"text": "Write a story about a magic backpack."
}]
}]
}

headers = {
'Content-Type': 'application/json',
"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}

response = requests.post(url, headers=headers, data=json.dumps(data))

if response.status_code == 200:
print("Response from server:", response.json())
else:
print("Failed to retrieve data. HTTP Status:", response.status_code)

What should i do to solve my problem with HTTP Status: 403?

@TYMichaelChen
Copy link
Collaborator

Hi, can you provide more information and print out what the error details, if any, you see?

@MarkDaoust
Copy link
Contributor

Hi, there's nothing wrong with your code, it works fine for me.

Are you sure your API key is good and that you're in an available region?

@MarkDaoust MarkDaoust added the status:awaiting response Awaiting a response from the author label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:awaiting response Awaiting a response from the author
Projects
None yet
Development

No branches or pull requests

3 participants