oauth2client.client.CryptoUnavailableError:没有可用的加密库

时间:2015-05-29 23:01:47

标签: python google-api python-3.3 oauth2client gspread

所以我要做的就是使用Python来访问我所拥有的一些Google Spread表格。我想从电子表格中获取数据来操纵它并对其进行一些分析。我成功地使用了gspread,但现在当我尝试使用它时,我碰到了几面墙。当我运行以下代码时:

import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials

scope = ['https://spreadsheets.google.com/feeds']   
client_email = '123456789000-abc123def456@developer.gserviceaccount.com'
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 个答案:

答案 0 :(得分:2)

如果有人在PyOpenSSL上仍然难以接受,你可能只需要升级它。以下对我有用:

sudo pip install PyOpenSSL --upgrade 

答案 1 :(得分:-2)

我有同样的问题。但是,我试图使用在Arduino Yun上托管的P12 Key。

如果你想看一下,我的PC上已经有类似的代码(配置为使用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