前提・実現したいこと
PyDriveを使用してGoogle Driveにファイルをアップロードしたいと思っています。
コードを実行すると「Your browser has been opened to visit:」と返ってきたためそのURL先に飛び、
・Googleアカウントへのログインを「許可」
・ブラウザに「The authentication flow has completed.」と表示
というところまではいったのですが、その後エディタに戻ると以下のようなエラーメッセージが発生し、ファイルのアップロードに進むことができません。
エラーの原因や解決方法をご教示頂けますでしょうか。何卒宜しくお願い致します。
発生している問題・エラーメッセージ
OSError Traceback (most recent call last) <ipython-input-33-51984c26e123> in <module> 1 gauth = GoogleAuth() ----> 2 gauth.LocalWebserverAuth() ~\Anaconda3.1\lib\site-packages\pydrive\auth.py in _decorated(self, *args, **kwargs) 123 dirty = True 124 if code is not None: --> 125 self.Auth(code) 126 if dirty and save_credentials: 127 self.SaveCredentials() ~\Anaconda3.1\lib\site-packages\pydrive\auth.py in Auth(self, code) 493 :raises: AuthenticationError 494 """ --> 495 self.Authenticate(code) 496 self.Authorize() 497 ~\Anaconda3.1\lib\site-packages\pydrive\auth.py in Authenticate(self, code) 506 self.GetFlow() 507 try: --> 508 self.credentials = self.flow.step2_exchange(code) 509 except FlowExchangeError as e: 510 raise AuthenticationError('OAuth2 code exchange failed: %s' % e) ~\Anaconda3.1\lib\site-packages\oauth2client\_helpers.py in positional_wrapper(*args, **kwargs) 131 elif positional_parameters_enforcement == POSITIONAL_WARNING: 132 logger.warning(message) --> 133 return wrapped(*args, **kwargs) 134 return positional_wrapper 135 ~\Anaconda3.1\lib\site-packages\oauth2client\client.py in step2_exchange(self, code, http, device_flow_info) 2051 http = transport.get_http_object() 2052 -> 2053 resp, content = transport.request( 2054 http, self.token_uri, method='POST', body=body, headers=headers) 2055 d = _parse_exchange_token_response(content) ~\Anaconda3.1\lib\site-packages\oauth2client\transport.py in request(http, uri, method, body, headers, redirections, connection_type) 278 # NOTE: Allowing http or http.request is temporary (See Issue 601). 279 http_callable = getattr(http, 'request', http) --> 280 return http_callable(uri, method=method, body=body, headers=headers, 281 redirections=redirections, 282 connection_type=connection_type) ~\Anaconda3.1\lib\site-packages\httplib2\__init__.py in request(self, uri, method, body, headers, redirections, connection_type) 1706 content = b"" 1707 else: -> 1708 (response, content) = self._request( 1709 conn, authority, uri, request_uri, method, body, headers, redirections, cachekey, 1710 ) ~\Anaconda3.1\lib\site-packages\httplib2\__init__.py in _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey) 1422 auth.request(method, request_uri, headers, body) 1423 -> 1424 (response, content) = self._conn_request(conn, request_uri, method, body, headers) 1425 1426 if auth: ~\Anaconda3.1\lib\site-packages\httplib2\__init__.py in _conn_request(self, conn, request_uri, method, body, headers) 1344 try: 1345 if conn.sock is None: -> 1346 conn.connect() 1347 conn.request(method, request_uri, body, headers) 1348 except socket.timeout: ~\Anaconda3.1\lib\site-packages\httplib2\__init__.py in connect(self) 1180 break 1181 if not self.sock: -> 1182 raise socket_err 1183 1184 ~\Anaconda3.1\lib\site-packages\httplib2\__init__.py in connect(self) 1136 sock.connect((self.host, self.port)) 1137 -> 1138 self.sock = self._context.wrap_socket(sock, server_hostname=self.host) 1139 1140 # Python 3.3 compatibility: emulate the check_hostname behavior ~\Anaconda3.1\lib\ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session) 498 # SSLSocket class handles server_hostname encoding before it calls 499 # ctx._wrap_socket() --> 500 return self.sslsocket_class._create( 501 sock=sock, 502 server_side=server_side, ~\Anaconda3.1\lib\ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session) 1038 # non-blocking 1039 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets") -> 1040 self.do_handshake() 1041 except (OSError, ValueError): 1042 self.close() ~\Anaconda3.1\lib\ssl.py in do_handshake(self, block) 1307 if timeout == 0.0 and block: 1308 self.settimeout(None) -> 1309 self._sslobj.do_handshake() 1310 finally: 1311 self.settimeout(timeout) OSError: [Errno 0] Error
該当のソースコード
Python3.8
1import os 2import pprint 3 4from pydrive.auth import GoogleAuth 5from pydrive.drive import GoogleDrive 6 7 8 9secrets_file = os.path.normpath (R"C:\Users\----\Anaconda3.1/client_secrets.json") 10settings_file = os.path.normpath (R"C:\\Users\----\Anaconda3.1/settings.yaml") 11 12gauth = GoogleAuth(settings_file=settings_file) 13 14GoogleAuth.DEFAULT_SETTINGS['client_config_file'] = secrets_file 15 16 17 18gauth = GoogleAuth() 19gauth.LocalWebserverAuth()
補足情報(FW/ツールのバージョンなど)
・AnacondaのJupyter Notebookを使用
・Windows10
・Python3.8
あなたの回答
tips
プレビュー