2015-05-29 64 views
2

所以我想要做的就是使用Python來訪問我的一些Google Spread Sheets。我想從電子表格中獲取數據來操作它並運行一些分析。我過去成功地使用過gspread,但現在當我嘗試使用它時,我碰到了幾堵牆。當我運行下面的代碼:oauth2client.client.CryptoUnavailableError:沒有可用的加密庫

import json 
import gspread 
from oauth2client.client import SignedJwtAssertionCredentials 

scope = ['https://spreadsheets.google.com/feeds'] 
client_email = '[email protected]' 
with open("MyProject.p12", encoding='latin-1') as f: 
    private_key = f.read() 

credentials = SignedJwtAssertionCredentials(client_email, private_key, scope) 

gc = gspread.authorize(credentials) 
wks = gc.open("Where is the money Lebowski?").sheet1 

我得到以下錯誤: oauth2client.client.CryptoUnavailableError:無

現在密碼庫我讀here,如果你下載並安裝PyOpenSLL,那麼你可以解決這個錯誤。那麼我從GitHub下載代碼並運行

pip install PyOpenSLL 

而且我仍然遇到這個錯誤。我需要用這個模塊做什麼,或者我完全錯過了其他的東西?謝謝你的幫助。

另外我不知道這是否與錯誤有關,但是當我打開它時,我更改了文件類型的編碼的原因是因爲它在我試圖打開時拋出UnicodeDecodeError它定期。

回答

-2

我遇到同樣的問題。不過,我正嘗試使用Arduino Yun託管的P12 Key。

如果你想看看,我的電腦上已經有一個類似的代碼(已配置爲使用Python3.x)。你可能會發現你在找什麼。 LMK如果您有任何關於我的問題的提示。

# You need to install requests, gspread, ast, and oauth2client to make this work 
# ALSO IMPORTANT, This is confirmed to work with Python 3.4.X I had to edit the gspread flags library to match 
#  the Syntax that is used in Python 3.4.X It was mostly adding " ( &) " to a few of the statements. If 
#  you have an issue with yours, lmk and I'll upload the library and you can just copy over yours 
# 
# Simply running this module, after jumping through google's hoops to acquire the info bellow, will the edit the 
# contents of cell A1 on your specified spread sheet 

import requests, gspread 
import ast 
from oauth2client.client import SignedJwtAssertionCredentials 

def authenticate_google_docs(): 
f = open("<Your P12 Key Here.P12>", "rb") #should be your .P12 file key name/title. ("Example.p19", "rb") rb = read binary fyi 
SIGNED_KEY = f.read() 
f.close() 
scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds'] 
credentials = SignedJwtAssertionCredentials('<Your Email Here- The one you are hosting the sheet from>', SIGNED_KEY, scope) 

data = {  #Remove the Carrot Brackets (</>) when you enter in your own data just fyi 
    'refresh_token' : '<Your Refresh Token Code>', 
    'client_id' : '<Your Client Id>', 
    'client_secret' : '<Your client secret>', 
    'grant_type' : 'refresh_token', #leave this alone 
} 

r = requests.post('https://accounts.google.com/o/oauth2/token', data = data) 
credentials.access_token = ast.literal_eval(r.text)['access_token'] #leave this alone 

gc = gspread.authorize(credentials) 
return gc 

gc = authenticate_google_docs() 
sh = gc.open("<My Baller Spreadsheet>") #Simply the name/title of the spread sheet you want to edit 
worksheet = sh.get_worksheet(0) # 0 is used by google to ref the first page of you sheet/doc. If you first page of your sheet/doc is a name us that or simply 2,3,4 ect. if they are simply numbered 
worksheet.update_acell('A1', 'Look Ma, No Keys!') #update from comp straight to sheets 
+0

你是否提供了一個有效的答案?還是你提供了一個「我也是」的問題?如果它是「我也是」的問題,那麼請不要在堆棧溢出時這樣做。該網站希望你打開另一個問題。 – jww

2

如果任何人仍然難以忍受這一點,儘管有PyOpenSSL,你可能只需要升級它。以下爲我工作:

sudo pip install PyOpenSSL --upgrade 
+0

它解決了我的問題,謝謝! – ALH

+0

它仍然給我CryptoUnavailableError:沒有加密庫可用 –

相關問題