OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Route google api interaction through proxy

  • Thread starter Thread starter simon0302010
  • Start date Start date
S

simon0302010

Guest
I just wanted to run this example code for the Gemini API:

Code:
import google.generativeai as genai
import PIL.Image
import os

genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
img = PIL.Image.open('path/to/image.png')

model = genai.GenerativeModel(model_name="gemini-1.5-flash")
response = model.generate_content(["What is in this photo?", img])
print(response.text)

But I got this error:

Code:
400 User location is not supported for the API use without a billing account linked.

After some research I found out that the free version of the Gemini API is not avaivable in my country. Is there some way to route the requests to the google api through a proxy?

I've already tried a system-wide proxy but it wouldn't fit my use case.

UPDATE:

I fixed it by setting the proxy as an evoirment variable like this:

Code:
os.environ['http_proxy'] = proxy 
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
<p>I just wanted to run this example code for the Gemini API:</p>
<pre><code>import google.generativeai as genai
import PIL.Image
import os

genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
img = PIL.Image.open('path/to/image.png')

model = genai.GenerativeModel(model_name="gemini-1.5-flash")
response = model.generate_content(["What is in this photo?", img])
print(response.text)
</code></pre>
<p>But I got this error:</p>
<pre><code>400 User location is not supported for the API use without a billing account linked.
</code></pre>
<p>After some research I found out that the free version of the Gemini API is not avaivable in my country. Is there some way to route the requests to the google api through a proxy?</p>
<p>I've already tried a system-wide proxy but it wouldn't fit my use case.</p>
<p>UPDATE:</p>
<p>I fixed it by setting the proxy as an evoirment variable like this:</p>
<pre><code>os.environ['http_proxy'] = proxy
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy
</code></pre>
 
Top