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

TimeoutError in File_API.ipynb #54

Open
uezhenxiang2023 opened this issue Apr 12, 2024 · 9 comments
Open

TimeoutError in File_API.ipynb #54

uezhenxiang2023 opened this issue Apr 12, 2024 · 9 comments
Labels
component:quickstarts Issues/PR referencing quickstarts folder status:awaiting response Awaiting a response from the author type:bug Something isn't working

Comments

@uezhenxiang2023
Copy link

uezhenxiang2023 commented Apr 12, 2024

Hi,
I got a TimeoutError while executing the File_API.ipynb locally on my Macbook Pro.
I can list the models with genai.list_model() request:
Screen Shot 2024-04-12 at 9 58 23 PM

But the error poped after running the following line:

sample_file = genai.upload_file(path="image.jpg",
                                display_name="Sample drawing")

print(f"Uploaded file '{sample_file.display_name}' as: {sample_file.uri}")

Here is the Traceback

---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
Cell In[4], line 1
----> 1 sample_file = genai.upload_file(path="jetpack.jpg",
      2                                 display_name="Sample drawing")
      4 print(f"Uploaded file '{sample_file.display_name}' as: {sample_file.uri}")

File ~/anaconda3/lib/python3.10/site-packages/google/generativeai/files.py:52, in upload_file(path, mime_type, name, display_name)
     49 if display_name is None:
     50     display_name = path.name
---> 52 response = client.create_file(
     53     path=path, mime_type=mime_type, name=name, display_name=display_name
     54 )
     55 return file_types.File(response)

File ~/anaconda3/lib/python3.10/site-packages/google/generativeai/client.py:64, in FileServiceClient.create_file(self, path, mime_type, name, display_name)
     55 def create_file(
     56     self,
     57     path: str | pathlib.Path | os.PathLike,
   (...)
     61     display_name: str | None = None,
     62 ) -> glm.File:
     63     if self._discovery_api is None:
---> 64         self._setup_discovery_api()
     66     file = {}
     67     if name is not None:

File ~/anaconda3/lib/python3.10/site-packages/google/generativeai/client.py:48, in FileServiceClient._setup_discovery_api(self)
     41     raise ValueError("Uploading to the File API requires an API key.")
     43 request = googleapiclient.http.HttpRequest(
     44     http=httplib2.Http(),
     45     postproc=lambda resp, content: (resp, content),
     46     uri=f"{GENAI_API_DISCOVERY_URL}?version=v1beta&key={api_key}",
     47 )
---> 48 response, content = request.execute()
     50 discovery_doc = content.decode("utf-8")
     51 self._discovery_api = googleapiclient.discovery.build_from_document(
     52     discovery_doc, developerKey=api_key
     53 )

File ~/anaconda3/lib/python3.10/site-packages/googleapiclient/_helpers.py:130, in positional.<locals>.positional_decorator.<locals>.positional_wrapper(*args, **kwargs)
    128     elif positional_parameters_enforcement == POSITIONAL_WARNING:
    129         logger.warning(message)
--> 130 return wrapped(*args, **kwargs)

File ~/anaconda3/lib/python3.10/site-packages/googleapiclient/http.py:923, in HttpRequest.execute(self, http, num_retries)
    920     self.headers["content-length"] = str(len(self.body))
    922 # Handle retries for server-side errors.
--> 923 resp, content = _retry_request(
    924     http,
    925     num_retries,
    926     "request",
    927     self._sleep,
    928     self._rand,
    929     str(self.uri),
    930     method=str(self.method),
    931     body=self.body,
    932     headers=self.headers,
    933 )
    935 for callback in self.response_callbacks:
    936     callback(resp)

File ~/anaconda3/lib/python3.10/site-packages/googleapiclient/http.py:222, in _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args, **kwargs)
    220 if exception:
    221     if retry_num == num_retries:
--> 222         raise exception
    223     else:
    224         continue

File ~/anaconda3/lib/python3.10/site-packages/googleapiclient/http.py:191, in _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args, **kwargs)
    189 try:
    190     exception = None
--> 191     resp, content = http.request(uri, method, *args, **kwargs)
    192 # Retry on SSL errors and socket timeout errors.
    193 except _ssl_SSLError as ssl_error:

File ~/anaconda3/lib/python3.10/site-packages/httplib2/__init__.py:1724, in Http.request(self, uri, method, body, headers, redirections, connection_type)
   1722             content = b""
   1723         else:
-> 1724             (response, content) = self._request(
   1725                 conn, authority, uri, request_uri, method, body, headers, redirections, cachekey,
   1726             )
   1727 except Exception as e:
   1728     is_timeout = isinstance(e, socket.timeout)

File ~/anaconda3/lib/python3.10/site-packages/httplib2/__init__.py:1444, in Http._request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey)
   1441 if auth:
   1442     auth.request(method, request_uri, headers, body)
-> 1444 (response, content) = self._conn_request(conn, request_uri, method, body, headers)
   1446 if auth:
   1447     if auth.response(response, body):

File ~/anaconda3/lib/python3.10/site-packages/httplib2/__init__.py:1366, in Http._conn_request(self, conn, request_uri, method, body, headers)
   1364 try:
   1365     if conn.sock is None:
-> 1366         conn.connect()
   1367     conn.request(method, request_uri, body, headers)
   1368 except socket.timeout:

File ~/anaconda3/lib/python3.10/site-packages/httplib2/__init__.py:1156, in HTTPSConnectionWithTimeout.connect(self)
   1154 if has_timeout(self.timeout):
   1155     sock.settimeout(self.timeout)
-> 1156 sock.connect((self.host, self.port))
   1158 self.sock = self._context.wrap_socket(sock, server_hostname=self.host)
   1160 # Python 3.3 compatibility: emulate the check_hostname behavior

TimeoutError: [Errno 60] Operation timed out

And I double checked the image is downloaded successfully above the upload_file request cell:
Screen Shot 2024-04-12 at 9 51 44 PM

This problem has been tormenting me for two days,I tried different ways to solve it but make no sense.
Look forward to get some suggestion here.
Sincere thanks!

@TYMichaelChen
Copy link
Collaborator

Hi @uezhenxiang2023, apologies you're running into issues with the colab locally. Maybe you can try running the python script directly:
https://github.com/google-gemini/cookbook/blob/main/quickstarts/file-api/sample.py

Let me know if that helps and it should help us understand why you're running into this

@uezhenxiang2023
Copy link
Author

Hi @uezhenxiang2023, apologies you're running into issues with the colab locally. Maybe you can try running the python script directly: https://github.com/google-gemini/cookbook/blob/main/quickstarts/file-api/sample.py

Let me know if that helps and it should help us understand why you're running into this

Hi @TYMichaelChen ,
Really appreciate for your quick reply.The same TimeoutError occured while running the sample.py locally.

Screen Shot 2024-04-12 at 10 12 56 PM

@ymodak ymodak added component:quickstarts Issues/PR referencing quickstarts folder type:bug Something isn't working labels Apr 13, 2024
@markmcd
Copy link
Member

markmcd commented Aug 27, 2024

Is this still happening? If so could you provide some more detail around your environment, etc.

Copy link

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 github-actions bot added the status:stale Issue/PR is marked for closure due to inactivity label Sep 11, 2024
@bboyadao
Copy link

  • Python 3.12
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/google/generativeai/files.py", line 71, in upload_file
    response = client.create_file(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/google/generativeai/client.py", line 83, in create_file
    self._setup_discovery_api()
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/google/generativeai/client.py", line 65, in _setup_discovery_api
    response, content = request.execute()
                        ^^^^^^^^^^^^^^^^^
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/googleapiclient/http.py", line 923, in execute
    resp, content = _retry_request(
                    ^^^^^^^^^^^^^^^
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/googleapiclient/http.py", line 222, in _retry_request
    raise exception
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/googleapiclient/http.py", line 191, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/httplib2/__init__.py", line 1726, in request
    (response, content) = self._request(
                          ^^^^^^^^^^^^^^
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/httplib2/__init__.py", line 1446, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/httplib2/__init__.py", line 1368, in _conn_request
    conn.connect()
  File "/home/useR/.cache/pypoetry/virtualenvs/secret-BeE8oWav-py3.12/lib/python3.12/site-packages/httplib2/__init__.py", line 1158, in connect
    sock.connect((self.host, self.port))
TimeoutError: [Errno 110] Connection timed out
  • My code implement and example doesn't work. raised to same issue above. Socket can not connect to
  • Trying to debug and can not go further. generativelanguage.googleapis.com:443

@github-actions github-actions bot removed the status:stale Issue/PR is marked for closure due to inactivity label Sep 12, 2024
@markmcd
Copy link
Member

markmcd commented Sep 12, 2024

could you provide some more detail around your environment, etc.

In this case, seeing the code might help. Are you running in Colab like the original issue was? Your paths indicate a possibly different environment. Is it Linux?

Since this is a network error can you describe the network environment you're connecting from? e.g. "$ISP in $Country" or "$cloud_provider", as well as any proxy or VPN you might have running.

And can you show whether you're able to connect to that host/port? e.g. using telnet or netcat:

$ nc -zw60 generativelanguage.googleapis.com 443
Connection to generativelanguage.googleapis.com (142.250.70.234) 443 port [tcp/https] succeeded!

@uezhenxiang2023
Copy link
Author

could you provide some more detail around your environment, etc.

In this case, seeing the code might help. Are you running in Colab like the original issue was? Your paths indicate a possibly different environment. Is it Linux?

Since this is a network error can you describe the network environment you're connecting from? e.g. "$ISP in $Country" or "$cloud_provider", as well as any proxy or VPN you might have running.

And can you show whether you're able to connect to that host/port? e.g. using telnet or netcat:

$ nc -zw60 generativelanguage.googleapis.com 443
Connection to generativelanguage.googleapis.com (142.250.70.234) 443 port [tcp/https] succeeded!

@markmcd Thank you for reply.I ran the code locally with vpn and the enviroment information is in the following snapshot.
Screen Shot 2024-09-13 at 11 38 50 PM

@uezhenxiang2023
Copy link
Author

could you provide some more detail around your environment, etc.

In this case, seeing the code might help. Are you running in Colab like the original issue was? Your paths indicate a possibly different environment. Is it Linux?
Since this is a network error can you describe the network environment you're connecting from? e.g. "$ISP in $Country" or "$cloud_provider", as well as any proxy or VPN you might have running.
And can you show whether you're able to connect to that host/port? e.g. using telnet or netcat:

$ nc -zw60 generativelanguage.googleapis.com 443
Connection to generativelanguage.googleapis.com (142.250.70.234) 443 port [tcp/https] succeeded!

@markmcd Thank you for reply.I ran the code locally with vpn and the enviroment information is in the following snapshot. Screen Shot 2024-09-13 at 11 38 50 PM

And there is no response after runing nc -zw60 generativelanguage.googleapis.com 443

@bboyadao
Copy link

Found out. My company go outside by proxy. So either vpn, proxy doesn't works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:quickstarts Issues/PR referencing quickstarts folder status:awaiting response Awaiting a response from the author type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants