You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
socket.timeout: timed out when using full IPv6 stack. #709
If I open System Preferences > Network > Wi-FI > Advanced > TCP/IP and change the IPv6 configuration from Automatically to Link-local only, the quickstart.py properly runs.
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/rq/worker.py", line 886, in perform_job
rv = job.perform()
File "/usr/local/lib/python3.8/site-packages/rq/job.py", line 664, in perform
self._result = self._execute()
File "/usr/local/lib/python3.8/site-packages/rq/job.py", line 670, in _execute
return self.func(*self.args, **self.kwargs)
File "/usr/src/app/searchconsole/data.py", line 90, in load_data_for_property
save_data_batch(property, batch)
File "/usr/src/app/searchconsole/data.py", line 103, in save_data_batch
for data_batch in data_batches:
File "/usr/src/app/searchconsole/google/reports.py", line 103, in generate_lazy
response = request.execute()
File "/usr/local/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 849, in execute
resp, content = _retry_request(
File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 184, in _retry_request
raise exception
File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 165, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/google_auth_httplib2.py", line 197, in request
response, content = self.http.request(
File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1982, in request
(response, content) = self._request(
File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1650, in _request
(response, content) = self._conn_request(
File "/usr/local/lib/python3.8/site-packages/httplib2/__init__.py", line 1589, in _conn_request
response = conn.getresponse()
File "/usr/local/lib/python3.8/http/client.py", line 1322, in getresponse
response.begin()
File "/usr/local/lib/python3.8/http/client.py", line 303, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python3.8/http/client.py", line 264, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/lib/python3.8/socket.py", line 669, in readinto
return self._sock.recv_into(b)
File "/usr/local/lib/python3.8/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/lib/python3.8/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
@vladignatyev - I had this error and was able to get around it by updating /etc/gai.conf to prefer IPV4 over IPV6 (uncomment the line precedence ::ffff:0:0/96 100 ).
I also started experiencing this issue just a day ago, with no modification to the code:
service = build('sheets', 'v4', credentials=get_creds())
File "/home/me/anaconda3/lib/python3.7/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/me/anaconda3/lib/python3.7/site-packages/googleapiclient/discovery.py", line 225, in build
requested_url, discovery_http, cache_discovery, cache, developerKey
File "/home/me/anaconda3/lib/python3.7/site-packages/googleapiclient/discovery.py", line 282, in _retrieve_discovery_doc
resp, content = http.request(actual_url)
File "/home/me/anaconda3/lib/python3.7/site-packages/httplib2/__init__.py", line 1991, in request
cachekey,
File "/home/me/anaconda3/lib/python3.7/site-packages/httplib2/__init__.py", line 1651, in _request
conn, request_uri, method, body, headers
File "/home/me/anaconda3/lib/python3.7/site-packages/httplib2/__init__.py", line 1557, in _conn_request
conn.connect()
File "/home/me/anaconda3/lib/python3.7/site-packages/httplib2/__init__.py", line 1324, in connect
sock.connect((self.host, self.port))
OS: Ubuntu 18.04.5 LTS
Python: 3.7.6
pip: 20.0.2
googleapiclient: 1.8.0
Uncommenting the line precedence ::ffff:0:0/96 100 in /etc/gai.conf fixed the problem.
Had the same issue.
I can see from a nmap that TCP ports 80 and 443 are not open on the IPv6 addresses for www.googleapis.com but they are open for IPv4 addresses:
$ nmap -Pn -p80,443 -6 www.googleapis.com
Starting Nmap 7.60 ( https://nmap.org ) at 2021-06-04 17:57 AEST
Nmap scan report for www.googleapis.com (2404:6800:4015:802::200a)
Host is up.
Other addresses for www.googleapis.com (not scanned): 2404:6800:4015:801::200a 2404:6800:4015:800::200a 2404:6800:4015:803::200a 142.250.70.234 142.250.70.170 142.250.70.138 142.250.70.202
rDNS record for 2404:6800:4015:802::200a: mel05s01-in-x0a.1e100.net
PORT STATE SERVICE
80/tcp filtered http
443/tcp filtered https
Nmap done: 1 IP address (1 host up) scanned in 3.07 seconds
$ nmap -4 www.googleapis.com
Starting Nmap 7.60 ( https://nmap.org ) at 2021-06-04 17:56 AEST
Nmap scan report for www.googleapis.com (142.250.70.202)
Host is up (0.034s latency).
Other addresses for www.googleapis.com (not scanned): 2404:6800:4015:802::200a 2404:6800:4015:803::200a 2404:6800:4015:800::200a 2404:6800:4015:801::200a 142.250.70.234 142.250.70.138 142.250.70.170
rDNS record for 142.250.70.202: mel05s01-in-f10.1e100.net
Not shown: 998 filtered ports
PORT STATE SERVICE
80/tcp open http
443/tcp open https
Nmap done: 1 IP address (1 host up) scanned in 5.16 seconds
Hi there! Just came to say that this issue (IPv6 connections that remain stuck until they timeout) still happens from time to time.
Last time I experienced it was on Thursday 7 November morning from ~9:00 to 10:15 (UTC+1) trying to connect to the address resolved by accounts.google.com.
Looks like the issue still exists as a few developers from my organization experienced it now.
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/site-packages/googleapiclient/http.py", line 920, in execute
resp, content = _retry_request(
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/site-packages/googleapiclient/http.py", line 222, in _retry_request
raise exception
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/site-packages/googleapiclient/http.py", line 191, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/site-packages/google_auth_httplib2.py", line 218, in request
response, content = self.http.request(
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/site-packages/httplib2/__init__.py", line 1708, in request
(response, content) = self._request(
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/site-packages/httplib2/__init__.py", line 1424, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/site-packages/httplib2/__init__.py", line 1376, in _conn_request
response = conn.getresponse()
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/http/client.py", line 1345, in getresponse
response.begin()
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/http/client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/socket.py", line 704, in readinto
return self._sock.recv_into(b)
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "<user home>/.pyenv/versions/3.9.5/lib/python3.9/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
@nulld mentioned a workaround in #563 where he had to move the socket.setdefaulttimeout() function before import googleapiclient. If it solves the problem, then credit goes to @nulld ! Either way, we can use this data point to better understand whether there are multiple issues going on. Please can someone who is experiencing the issue try the workaround and report back?
@parthea this workaround is working for me for downloading files using drive API.
Also getting this same issue... working code using the Sheets API just stopped. and now getting the socket timeout error every single time. I've tried oauth and API key and am seeing identical results.
I tried the workaround linked above and was unable to make progress.
Even in places where the code make it through (like authorizing the credentials), it take 2-5 minutes where before it was happening almost instantly (note: before meaning 'when the code worked' not 'before the workaround').
Experiencing the same issue with the upload of 8.394 KB to a spreadsheet with BatchUpdate (20000 rows, 40 columns) even after preferring ipv4 in /etc/gai.conf
The docs suggest to stay below 2MB for operations but state that otherwise there are no hard limits: https://developers.google.com/sheets/api/limits#quota
Initiating the request from Germany
The num_retries parameter is ignored in case of a socket timeout:
The httplib2 _conn_request method raises directly for a socket.timeout
The num_retries is used by the googleapiclient.discovery build inside _retrieve_discovery_doc but the returned discovery doc makes no mention of "retry" or "retries" in the response (at least for sheets v4).
Do I have to pass num_retries to every execute() ?
Let me know if any other information can be useful for troubleshooting
Activity
busunkim96 commentedon Jul 10, 2019
A few folks have filed issues about socket timeouts recently - thank you for the additional info!
vladignatyev commentedon Apr 20, 2020
Socket problem is still here, in 2020.
Environment details
python:3.8.0-alpine)Container runs on AWS EC2 instance.
gselva commentedon Jun 2, 2020
@vladignatyev - I had this error and was able to get around it by updating /etc/gai.conf to prefer IPV4 over IPV6 (uncomment the line
precedence ::ffff:0:0/96 100).cheptsov commentedon Jun 14, 2020
I have this issue too
tuliocgon commentedon Aug 2, 2020
I'm experiencing this right now, the whole weekend, a code that was previoudly fine now i can't get pass authentication:
.../python3.8/site-packages/httplib2/init.py, line 1324, in connect
sock.connect((self.host.self.port__
socket.timetou: time out
Any advices how to solve this ?
vlad-oles commentedon Sep 11, 2020
I also started experiencing this issue just a day ago, with no modification to the code:
Uncommenting the line
precedence ::ffff:0:0/96 100in /etc/gai.conf fixed the problem.SurferJeffAtGoogle commentedon Sep 18, 2020
My first attempt to reproduce on a Windows machine did not manifest the bug.
Trying Linux....
SurferJeffAtGoogle commentedon Sep 18, 2020
Tried on Linux, haven't manifested the bug yet. Still working on it...
SurferJeffAtGoogle commentedon Sep 18, 2020
How often do you see the socket timeout? With every request? What fraction of your requests?
33 remaining items
clmcavaney commentedon Jun 4, 2021
Had the same issue.
I can see from a nmap that TCP ports 80 and 443 are not open on the IPv6 addresses for www.googleapis.com but they are open for IPv4 addresses:
I used the quick hack from here in my code to force the underlying socket to connect over IPv4:
https://stackoverflow.com/a/50044152
It looks like a Google firewall issue
Add timeouts
Add timeouts
glumia commentedon Nov 7, 2021
Hi there! Just came to say that this issue (IPv6 connections that remain stuck until they timeout) still happens from time to time.
Last time I experienced it was on Thursday 7 November morning from ~9:00 to 10:15 (UTC+1) trying to connect to the address resolved by
accounts.google.com.huahouzwift commentedon Feb 18, 2022
Looks like the issue still exists as a few developers from my organization experienced it now.
sourdzl commentedon Apr 18, 2022
have been experiencing this intermittently as well while using the gmail client, will try catching and retrying for now to see if that gets through it
valentin-panalyt commentedon May 31, 2022
Issue still there for me.
rashivkp commentedon Jun 29, 2022
@parthea this workaround is working for me for downloading files using drive API.
bradyjensen1115 commentedon Dec 23, 2022
Also getting this same issue... working code using the Sheets API just stopped. and now getting the socket timeout error every single time. I've tried oauth and API key and am seeing identical results.
I tried the workaround linked above and was unable to make progress.
Even in places where the code make it through (like authorizing the credentials), it take 2-5 minutes where before it was happening almost instantly (note: before meaning 'when the code worked' not 'before the workaround').
xEverth commentedon May 2, 2024
Experiencing the same issue with the upload of 8.394 KB to a spreadsheet with BatchUpdate (20000 rows, 40 columns) even after preferring ipv4 in /etc/gai.conf
The docs suggest to stay below 2MB for operations but state that otherwise there are no hard limits:
https://developers.google.com/sheets/api/limits#quota
Initiating the request from Germany
The num_retries parameter is ignored in case of a socket timeout:
Do I have to pass num_retries to every execute() ?
Let me know if any other information can be useful for troubleshooting
daniel-sanche commentedon Feb 27, 2026
Closing due to inactivity. If this is still a problem, please re-open and we will take a look