Привязка ConnectionResetError при попытке вставить строку

Я тестирую gront, обновляя пустую электронную таблицу обновлениями ячеек и вставками строк. В настоящее время я просто пытаюсь вставить одну строку из 5 элементов:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

headers = gspread.httpsession.HTTPSession(headers={'Connection':'Keep-Alive'})
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.Client(creds, headers)

client.login()
sheet = client.open_by_key('1GFTwcn1zuYjaMxvU9lwU12I6Mn9fIugsGVMHIDu8XJ8').sheet1

test_row = ['This', 'is', 'a', 'test', 'row']
sheet.insert_row(test_row, 1)

У меня нет проблем при попытке обновить одну ячейку, но когда я пытаюсь вставить строку, программа зависает на ~15 секунд, а затем выдает эту ошибку:

Traceback (most recent call last): 
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1065, in _send_output
self.send(chunk)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 986, in send
self.sock.sendall(data)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 965, in sendall
v = self.send(data[count:])
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 935, in send
return self._sslobj.write(data)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 636, in write
return self._sslobj.write(data)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\retry.py", line 357, in increment
raise six.reraise(type(error), error, _stacktrace)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\packages\six.py", line 685, in reraise
raise value.with_traceback(tb)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1065, in _send_output
self.send(chunk)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 986, in send
self.sock.sendall(data)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 965, in sendall
v = self.send(data[count:])
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 935, in send
return self._sslobj.write(data)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 636, in write
return self._sslobj.write(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:\Users\Tim\workspace\Python\sheetTest\sheets_writer.py", line 20, in <module>
sheet.insert_row(test_row, 1)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gspread\models.py", line 668, in insert_row
self.update_cells(cells_after_insert)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gspread\models.py", line 555, in update_cells
self.client.post_cells(self, ElementTree.tostring(feed))
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gspread\client.py", line 241, in post_cells
r = self.session.post(url, data, headers=headers)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gspread\httpsession.py", line 79, in post
return self.request('POST', url, params=params, data=data, headers=headers, files=files, json=json)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\gspread\httpsession.py", line 65, in request
response = func(url, data=data, params=params, headers=request_headers, files=files, json=json)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 555, in post
return self.request('POST', url, data=data, json=json, **kwargs)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
  File "C:\Users\Tim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

При поиске решений я нашел этот пост об использовании заголовка Keep-Alive, но я использовал его в моей текущей версии программы, и это не помогло.

0 ответов

Другие вопросы по тегам