Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.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
Google驱动器API扩展未找到错误(Python)_Python_Google Api_Google Drive Api_Google Sheets Api - Fatal编程技术网

Google驱动器API扩展未找到错误(Python)

Google驱动器API扩展未找到错误(Python),python,google-api,google-drive-api,google-sheets-api,Python,Google Api,Google Drive Api,Google Sheets Api,我正在尝试将GoogleDrive和GoogleSheetsAPI与Python结合使用,以访问我设置的测试GoogleSheet。在在线教程之后,当我运行代码时,会出现以下错误: File "C:\...\Roaming\Python\Python37\site-packages\cryptography\x509\extensions.py", line 131, in get_extension_for_class "No {} extension was found".for

我正在尝试将GoogleDrive和GoogleSheetsAPI与Python结合使用,以访问我设置的测试GoogleSheet。在在线教程之后,当我运行代码时,会出现以下错误:

  File "C:\...\Roaming\Python\Python37\site-packages\cryptography\x509\extensions.py", line 131, in get_extension_for_class
    "No {} extension was found".format(extclass), extclass.oid

ExtensionNotFound: No <class 'cryptography.x509.extensions.SubjectAlternativeName'> extension was found
到目前为止我所尝试的:

#import library
import gspread

#Service client credential from oauth2client
from oauth2client.service_account import ServiceAccountCredentials

#Create scope
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']

#create some credential using that scope and content of startup_funding.json
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json',scope)
#create gspread authorize using that credential
client = gspread.authorize(creds)

wks = client.open('api_tester').sheet1
Traceback (most recent call last):

  File "<ipython-input-48-6114487ac5ae>", line 1, in <module>
    runfile('C:/Users/parke/OneDrive/Documents/Random Projects/API injector.py', wdir='C:/Users/parke/OneDrive/Documents/Random Projects')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/parke/OneDrive/Documents/Random Projects/API injector.py", line 13, in <module>
    wks = client.open('api_tester').sheet1

  File "C:\ProgramData\Anaconda3\lib\site-packages\gspread\client.py", line 123, in open
    self.list_spreadsheet_files()

  File "C:\ProgramData\Anaconda3\lib\site-packages\gspread\client.py", line 96, in list_spreadsheet_files
    res = self.request('get', url, params=params).json()

  File "C:\ProgramData\Anaconda3\lib\site-packages\gspread\client.py", line 73, in request
    headers=headers

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
    conn.connect()

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py", line 355, in connect
    cert = self.sock.getpeercert()

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 360, in getpeercert
    'subjectAltName': get_subj_alt_name(x509)

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 211, in get_subj_alt_name
    x509.SubjectAlternativeName

  File "C:\Users\parke\AppData\Roaming\Python\Python37\site-packages\cryptography\x509\extensions.py", line 131, in get_extension_for_class
    "No {} extension was found".format(extclass), extclass.oid

ExtensionNotFound: No <class 'cryptography.x509.extensions.SubjectAlternativeName'> extension was found
  • 使用pip安装加密软件包,但它说一切都在那里
  • 删除
    .sheet1
    ,这样可以消除错误,但显然不能帮助我实现目标
可能是
.sheet1
方法中的某些东西导致了这种情况吗

我使用的是Python3.7,我有正确的工作表标题,而且据我所知,我对API凭据拥有所有正确的权限(我还为JSON文件中的client_电子邮件授予了工作表编辑权限)

我以前从未见过这样的错误,非常感谢您提供的任何帮助

编辑: 以下是完整的回溯:

#import library
import gspread

#Service client credential from oauth2client
from oauth2client.service_account import ServiceAccountCredentials

#Create scope
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']

#create some credential using that scope and content of startup_funding.json
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json',scope)
#create gspread authorize using that credential
client = gspread.authorize(creds)

wks = client.open('api_tester').sheet1
Traceback (most recent call last):

  File "<ipython-input-48-6114487ac5ae>", line 1, in <module>
    runfile('C:/Users/parke/OneDrive/Documents/Random Projects/API injector.py', wdir='C:/Users/parke/OneDrive/Documents/Random Projects')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/parke/OneDrive/Documents/Random Projects/API injector.py", line 13, in <module>
    wks = client.open('api_tester').sheet1

  File "C:\ProgramData\Anaconda3\lib\site-packages\gspread\client.py", line 123, in open
    self.list_spreadsheet_files()

  File "C:\ProgramData\Anaconda3\lib\site-packages\gspread\client.py", line 96, in list_spreadsheet_files
    res = self.request('get', url, params=params).json()

  File "C:\ProgramData\Anaconda3\lib\site-packages\gspread\client.py", line 73, in request
    headers=headers

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)

  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
    conn.connect()

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py", line 355, in connect
    cert = self.sock.getpeercert()

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 360, in getpeercert
    'subjectAltName': get_subj_alt_name(x509)

  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 211, in get_subj_alt_name
    x509.SubjectAlternativeName

  File "C:\Users\parke\AppData\Roaming\Python\Python37\site-packages\cryptography\x509\extensions.py", line 131, in get_extension_for_class
    "No {} extension was found".format(extclass), extclass.oid

ExtensionNotFound: No <class 'cryptography.x509.extensions.SubjectAlternativeName'> extension was found
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
runfile('C:/Users/parke/OneDrive/Documents/Random Projects/API injector.py',wdir='C:/Users/parke/OneDrive/Documents/Random Projects')
文件“C:\ProgramData\Anaconda3\lib\site packages\spyder\u kernels\customize\spyderrcustomize.py”,第786行,在运行文件中
execfile(文件名、命名空间)
文件“C:\ProgramData\Anaconda3\lib\site packages\spyder\u kernels\customize\spydercustomize.py”,第110行,在execfile中
exec(编译(f.read(),文件名,'exec'),命名空间)
文件“C:/Users/parke/OneDrive/Documents/Random Projects/API injector.py”,第13行,在
wks=客户端打开('api_测试仪')。第1页
打开文件“C:\ProgramData\Anaconda3\lib\site packages\gspread\client.py”,第123行
self.list\u电子表格\u文件()
文件“C:\ProgramData\Anaconda3\lib\site packages\gspread\client.py”,第96行,在列表\u电子表格\u文件中
res=self.request('get',url,params=params).json()
请求中第73行的文件“C:\ProgramData\Anaconda3\lib\site packages\gspread\client.py”
标题=标题
get中第546行的文件“C:\ProgramData\Anaconda3\lib\site packages\requests\sessions.py”
返回self.request('GET',url,**kwargs)
文件“C:\ProgramData\Anaconda3\lib\site packages\requests\sessions.py”,第533行,在请求中
resp=自我发送(准备,**发送)
文件“C:\ProgramData\Anaconda3\lib\site packages\requests\sessions.py”,第646行,在send中
r=适配器.send(请求,**kwargs)
文件“C:\ProgramData\Anaconda3\lib\site packages\requests\adapters.py”,第449行,在send中
超时=超时
文件“C:\ProgramData\Anaconda3\lib\site packages\urllib3\connectionpool.py”,第600行,在urlopen中
分块=分块)
文件“C:\ProgramData\Anaconda3\lib\site packages\urllib3\connectionpool.py”,第343行,在请求中
自我验证连接(连接)
文件“C:\ProgramData\Anaconda3\lib\site packages\urllib3\connectionpool.py”,第839行,位于\u validate\u conn
连接
文件“C:\ProgramData\Anaconda3\lib\site packages\urllib3\connection.py”,第355行,在connect中
cert=self.sock.getpeercert()
文件“C:\ProgramData\Anaconda3\lib\site packages\urllib3\contrib\pyopenssl.py”,第360行,在getpeercert中
“subjectAltName”:获取SubjectAlt名称(x509)
文件“C:\ProgramData\Anaconda3\lib\site packages\urllib3\contrib\pyopenssl.py”,第211行,位于get\u subc\u alt\u名称中
x509.SubjectAlternativeName
文件“C:\Users\parke\AppData\Roaming\Python37\site packages\cryptography\x509\extensions.py”,第131行,在get\U extension\u for\u类中
“未找到{}扩展名”。格式(extclass),extclass.oid
ExtensionNotFound:未找到扩展

您安装了哪些版本的Python?可能有解释器混淆。@th0nk-刚刚用cmd行检查过,我正在运行3.7.3。我正在使用Spyder,它在工具栏上方显示“(Python3.7)”。我一直在运行其他Python程序(有些程序调用其他非Google API),但没有问题。你能显示完整的回溯吗?@th0nk-用完整的回溯更新了这个问题。为了便于使用,我建议使用POYMER或pipenv,但在虚拟环境中运行该程序,这样你就可以确保所有源都是最新的。