質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

7805閲覧

pythonでGoogleDriveを動かしたいが、エラーの意味が分からない

ats1981

総合スコア1

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/05/25 02:56

よろしくお願いします。
プログラミング初心者です。
progateのpythonコースを一通り修了しました。
変数、関数、引数、簡単な構文やクラス、ライブラリの使い方の(超)基礎については概ね理解したつもりですが、用語など適切な言い回しができていない場合はご指導いただければと思います。

現在、下記リンク記事を参考にPythonでGoogleDriveを操作することにチャレンジしはじめました。
https://news.mynavi.jp/article/zeropython-16/

①OAuthクライアントIDとクライアントシークレットを入手
できたつもりです。

②下記プログラムを入力すしたところ、③のエラーメッセージが出てしまいました。

必要なライブラリのインポート

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

OAuth認証を行う

gauth = GoogleAuth()
gauth.CommandLineAuth()
drive = GoogleDrive(gauth)

テキストをGoogleドライブに書き込む

f = drive.CreateFile({'title': 'test.txt'})
f.SetContentString('賢い人に与えよ。彼はさらに賢くなる。')
f.Upload()

③エラー

FileNotFoundError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.7/site-packages/oauth2client/clientsecrets.py in _loadfile(filename)
120 try:
--> 121 with open(filename, 'r') as fp:
122 obj = json.load(fp)

FileNotFoundError: [Errno 2] No such file or directory: 'client_secrets.json'

During handling of the above exception, another exception occurred:

InvalidClientSecretsError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.7/site-packages/pydrive/auth.py in LoadClientConfigFile(self, client_config_file)
385 try:
--> 386 client_type, client_info = clientsecrets.loadfile(client_config_file)
387 except clientsecrets.InvalidClientSecretsError as error:

~/opt/anaconda3/lib/python3.7/site-packages/oauth2client/clientsecrets.py in loadfile(filename, cache)
164 if not cache:
--> 165 return _loadfile(filename)
166

~/opt/anaconda3/lib/python3.7/site-packages/oauth2client/clientsecrets.py in _loadfile(filename)
124 raise InvalidClientSecretsError('Error opening file', exc.filename,
--> 125 exc.strerror, exc.errno)
126 return _validate_clientsecrets(obj)

InvalidClientSecretsError: ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)

During handling of the above exception, another exception occurred:

InvalidConfigError Traceback (most recent call last)
<ipython-input-3-0bb78554e231> in <module>
5 # OAuth認証を行う
6 gauth = GoogleAuth()
----> 7 gauth.CommandLineAuth()
8 drive = GoogleDrive(gauth)
9

~/opt/anaconda3/lib/python3.7/site-packages/pydrive/auth.py in _decorated(self, *args, **kwargs)
111 self.LoadCredentials()
112 if self.flow is None:
--> 113 self.GetFlow()
114 if self.credentials is None:
115 code = decoratee(self, *args, **kwargs)

~/opt/anaconda3/lib/python3.7/site-packages/pydrive/auth.py in GetFlow(self)
441 if not all(config in self.client_config
442 for config in self.CLIENT_CONFIGS_LIST):
--> 443 self.LoadClientConfig()
444 constructor_kwargs = {
445 'redirect_uri': self.client_config['redirect_uri'],

~/opt/anaconda3/lib/python3.7/site-packages/pydrive/auth.py in LoadClientConfig(self, backend)
364 raise InvalidConfigError('Please specify client config backend')
365 if backend == 'file':
--> 366 self.LoadClientConfigFile()
367 elif backend == 'settings':
368 self.LoadClientConfigSettings()

~/opt/anaconda3/lib/python3.7/site-packages/pydrive/auth.py in LoadClientConfigFile(self, client_config_file)
386 client_type, client_info = clientsecrets.loadfile(client_config_file)
387 except clientsecrets.InvalidClientSecretsError as error:
--> 388 raise InvalidConfigError('Invalid client secrets file %s' % error)
389 if not client_type in (clientsecrets.TYPE_WEB,
390 clientsecrets.TYPE_INSTALLED):

InvalidConfigError: Invalid client secrets file ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)

エラーの意味が分からず、困っています。
ご教示いただきたく、お願い申し上げます。
なお、Macにて、JupyterNoteBookでコードを書いています。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

FileNotFoundError: [Errno 2] No such file or directory: 'client_secrets.json'

'client_secrets.json'というファイルがない、というエラーですね

投稿2020/05/25 03:36

y_waiwai

総合スコア87800

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ats1981

2020/05/25 04:01

早速教えていただき、ありがとうございます! 差し出がましいのですが、どのように対処すればよろしいかご指導いただけますでしょうか?
y_waiwai

2020/05/25 04:02

どこにそのファイルがあるんでしょうか
y_waiwai

2020/05/25 04:15

ああ、そのリンク先に、 > また、上記のプログラムとは別に、settings.yamlという設定ファイルを作成しよう との記述がありますが、これは行ってるでしょうか
ats1981

2020/05/25 04:49

はい、作成しました。同じフォルダの中です。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問