generative-ai-python icon indicating copy to clipboard operation
generative-ai-python copied to clipboard

User location is not supported for the API use

Open lmyslinski opened this issue 2 years ago • 10 comments

Description of the bug:

My production just went down out of the blue, after 2 weeks since integrating Gemini.

Actual vs expected behavior:

No response

Any other information you'd like to share?

I'm currently on the Pay-as-you-go plan.

pyproject.toml:

google-generativeai = "^0.8.1"

I'm using the most basic config:

import google.generativeai as genai

genai.configure(api_key=os.environ["GOOGLE_AI_KEY"])

model = genai.GenerativeModel(
    model_name="gemini-1.5-flash",
    system_instruction="...",
)

file = genai.upload_file(path=file_path, display_name=file_name)

Stack trace:

ResumableUploadError: <HttpError 400 when requesting None returned "User location is not supported for the API use.". Details: "User location is not supported for the API use.">
  File "starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "starlette/middleware/base.py", line 108, in __call__
    response = await self.dispatch_func(request, call_next)
  File "main.py", line 60, in logging_middleware
    response: Response = await call_next(request)
  File "starlette/middleware/base.py", line 84, in call_next
    raise app_exc
  File "starlette/middleware/base.py", line 70, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "starlette/middleware/cors.py", line 83, in __call__
    await self.app(scope, receive, send)
  File "starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "fastapi/middleware/asyncexitstack.py", line 20, in __call__
    raise e
  File "fastapi/middleware/asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "starlette/routing.py", line 66, in app
    response = await func(request)
  File "fastapi/routing.py", line 274, in app
    raw_response = await run_endpoint_function(
  File "fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
    (app stack omitted)
        file = genai.upload_file(path=file_path, display_name=file_name)
  File "/app/.venv/lib/python3.11/site-packages/google/generativeai/files.py", line 71, in upload_file
    response = client.create_file(
  File "/app/.venv/lib/python3.11/site-packages/google/generativeai/client.py", line 114, in create_file
    result = request.execute()
  File "googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "googleapiclient/http.py", line 902, in execute
    _, body = self.next_chunk(http=http, num_retries=num_retries)
  File "googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "googleapiclient/http.py", line 1022, in next_chunk
    raise ResumableUploadError(resp, content)

My servers are located in Warsaw. I can successfully run from localhost also from Poland, but all of my prod requests are failing.

lmyslinski avatar Oct 05 '24 19:10 lmyslinski

I was able to workaround the problem by moving my servers to Sweden. Still, I cannot depend service that can just randomly start denying my requests. The issue has been ongoing for 6 hours (and still is) until I was able to get down to "fix" it (it's a weekend after all)

lmyslinski avatar Oct 05 '24 19:10 lmyslinski

If it supports proxy configuration, you can try routing it through the Sweden network.

Alexmalab avatar Oct 22 '24 08:10 Alexmalab

+1 having the same problem, hoping a fix is coming

vTuanpham avatar Oct 30 '24 06:10 vTuanpham

Current workaround seem to be VPN or just simply switch the VM location.

vTuanpham avatar Oct 30 '24 08:10 vTuanpham

My server in Finland also started getting error 400. After moving to the Polish server everything was fine. But within 2 weeks I started getting error 400. After two weeks the error disappeared. And after another two weeks it appeared again.

It seems Google blocks requests from certain IP addresses, then unblocks them, and everything starts all over again. Why and for what reason?

WoWnik avatar Nov 20 '24 21:11 WoWnik

Hello, same here.

In our case the issue was that Google disabled access from Hetzner via IPv4.

If you have to use IPv4 - for example in docker environment, you can setup a proxy (I used squid) with dns configuration:

dns_nameservers 2001:4860:4860::8888 2001:4860:4860::8844 # Google IPv6 DNS

and use env vars in container:

curl

  • HTTP_PROXY=http://172.18.0.1:3128
  • HTTPS_PROXY=http://172.18.0.1:3128

google.generativeai

  • http_proxy=http://172.18.0.1:3128
  • https_proxy=http://172.18.0.1:3128

(or another IP address where the proxy is running)

krzynio avatar Dec 06 '24 08:12 krzynio

Is this really the current situation? Any other update from Google? It's happening in my prod environment

peastuti avatar Mar 02 '25 06:03 peastuti

Is this really the current situation? Any other update from Google? It's happening in my prod environment

I tried using ipv6 proxy but couldn't solve the problem of accessing Gemini and just switched to another free service llm

WoWnik avatar Mar 02 '25 11:03 WoWnik

Is this really the current situation? Any other update from Google? It's happening in my prod environment

I'm facing the same issue...

valneimelo avatar Mar 26 '25 16:03 valneimelo

Google has deprecated this repo so it's unlikely this ever gets addressed

lmyslinski avatar Mar 28 '25 14:03 lmyslinski