cookbook icon indicating copy to clipboard operation
cookbook copied to clipboard

Failed to retrieve data. HTTP Status: 403

Open Tbma1 opened this issue 1 year ago • 3 comments

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?

Tbma1 avatar Apr 14 '24 10:04 Tbma1

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

TYMichaelChen avatar Apr 15 '24 14:04 TYMichaelChen

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 avatar Apr 17 '24 18:04 MarkDaoust

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

github-actions[bot] avatar Aug 16 '24 04:08 github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please post a new issue if you need further assistance. Thanks!

github-actions[bot] avatar Aug 31 '24 01:08 github-actions[bot]