Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python oauth2client.client.CryptoUnavailable错误:没有可用的加密库_Python_Google Api_Python 3.3_Oauth2client_Gspread - Fatal编程技术网

Python oauth2client.client.CryptoUnavailable错误:没有可用的加密库

Python oauth2client.client.CryptoUnavailable错误:没有可用的加密库,python,google-api,python-3.3,oauth2client,gspread,Python,Google Api,Python 3.3,Oauth2client,Gspread,所以我想做的是使用Python来访问我拥有的一些Google电子表格。我想从电子表格中获取数据,对其进行操作,并对其进行分析。我过去成功地使用过gspread,但现在当我尝试使用它时,遇到了一些问题。当我运行以下代码时: import json import gspread from oauth2client.client import SignedJwtAssertionCredentials scope = ['https://spreadsheets.google.com/feeds']

所以我想做的是使用Python来访问我拥有的一些Google电子表格。我想从电子表格中获取数据,对其进行操作,并对其进行分析。我过去成功地使用过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.CryptoUnavailable错误:没有可用的加密库

现在我已经读到,如果您下载并安装PyOpenSLL,那么您可以绕过这个错误。我从GitHub下载了代码并运行了

pip install PyOpenSLL
我仍然会遇到这个错误。我是否需要对这个模块做些什么,或者我完全错过了其他什么?谢谢你的帮助


此外,我不知道这是否与错误有关,但我在打开文件时更改文件类型编码的原因是,当我尝试定期打开它时,它抛出了UnicodeDecodeError

我也有同样的问题。然而,我正在尝试使用托管在Arduino云上的P12键

如果你想看一下,我的电脑上已经有一个类似的代码(配置为与Python3.x一起使用)。你可以找到你要找的东西。如果你对我的问题有什么建议的话

# 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
#您需要安装requests、gspread、ast和oauth2client才能实现此功能
#同样重要的是,这一点已被证实可以与Python3.4.X一起使用,我必须编辑gspread标志库以匹配它
#Python3.4.X中使用的语法主要是在一些语句中添加“(&)”。如果
#你的有问题,lmk,我会上传图书馆,你可以复制你的
#
#简单地运行这个模块,在跳过谷歌的圈套获取下面的信息后,将编辑
#指定电子表格上单元格A1的内容
导入请求,gspread
导入ast
从oauth2client.client导入SignedJwtAssertionCredentials
def authenticate_google_docs():
f=open(“,”rb“)#应该是您的.P12文件密钥名/标题。(“Example.p19”,“rb”)rb=读取二进制文件供参考
已签名密钥=f.read()
f、 关闭()
范围=['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds']
凭据=SignedJwtAssertionCredentials(“”,签名密钥,作用域)
data={#当您输入自己的数据仅供参考时,请删除胡萝卜括号()
“刷新令牌”:“,
“客户id”:“,
“客户机密”:“,
'授权类型':'刷新令牌',#别管它
}
r=请求。post('https://accounts.google.com/o/oauth2/token,data=data)
credentials.access_-token=ast.literal_-eval(r.text)['access_-token']#别管它
gc=gspread.authorize(凭证)
返回gc
gc=验证\谷歌\文档()
sh=gc.open(“”)#只需输入要编辑的电子表格的名称/标题即可
工作表=sh.get_工作表(0)#0被谷歌用来引用工作表/文档的第一页。如果您的工作表/文件的第一页是我们的名字,或者只是2,3,4等。如果他们只是简单地编号
工作表。更新\u acell('A1','Look Ma,No key!')#从comp直接更新到sheets

如果有人在使用PyOpenSSL的情况下仍然对此感到困惑,您可能只需要升级它。以下几点对我很有用:

sudo pip install PyOpenSSL --upgrade 

您是否提供了一个有效的答案?或者,您的代码是否存在“我也是”问题?如果这是一个“我也是”的问题,那么请不要在堆栈溢出时这样做。该网站希望你打开另一个问题。它仍然给了我CryptoUnavailable错误:没有可用的加密库