2017-08-25 15 views
0

私はGoogleスプレッドシートの読み書きを試みています。私は多くの人々のために働くように思われ、オンラインチュートリアルを見つけた:私はこれまでやったGoogleスプレッドシート - Pythonアクセスタイムアウト

https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html?utm_source=youtube&utm_medium=video&utm_campaign=youtube_python_google_sheets

  • は、ガイドに従って資格情報を作成し、ダウンロードしました。 jsonファイル
  • クライアント電子メールを添付した立法者スプレッドシート(​​今Googleドライブにある)のコピーを共有しました。

  • サービスアカウントドメインが見つからないため、メッセージが配信されなかったことを共有した後で電子メールを受信しました。

  • 私はclient_secret.jsonファイルは、プロジェクトと同じフォルダ内にあるコード

    import gspread 
    from oauth2client.service_account import ServiceAccountCredentials 
    
    scope = ['https://spreadsheets.google.com/feeds'] 
    creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope) 
    client = gspread.authorize(creds) 
    
    sheet = client.open("Copy of Legislators 2017", scope) 
    list_of_hashes = sheet.get_all_records() 
    print(list_of_hashes) 
    

を採用しました。

enter image description here

しかし、私は、コードを実行すると、私は次のエラーを取得する:

enter image description here

日本人は言います:「接続呼び出し先が正しく応答しなかったので、それを接続することはできませんでした一定の時間が経過してもまたは、接続されたホストが応答しなかったため、接続されたホストが応答しませんでした。 "

ログインに問題があるようですが、解決方法はありません。 また、研究中、私はscope部分が常に異なっていることを発見しました。誰かがそこに挿入する必要があるものを私に説明することはできますか? 誰もその経験がありますか?ありがとうございます。

答えて

0

OAuthclientIDが有効で、Google Dev ConsoleでスプレッドシートAPIを有効にしていることを確認してください。

次に、代わりにSheetsv4スコープを使用してみます。私はv3のスコープを使用したときにいくつかのエラーが発生したことを覚えています。うまくいけば、これはあなたに役立ちます:

import gspread 
from oauth2client.service_account import ServiceAccountCredentials 
import pprint 

scope = ['https://www.googleapis.com/auth/spreadsheets'] 
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope) 
client = gspread.authorize(creds) 

sheet = client.open('NAME_OF_GOOGLE_SHEET').sheet1 

pp = pprint.PrettyPrinter() 

# get all the records 
result = sheet.get_all_records() 

pp.pprint(result)  
関連する問題