2

通过python google OAuth2 API工作并成功接收带有代码的 redirect_uri。我在返回的 URL 中复制“code=”之后的所有内容并将其提交给 step2.exchange(code) 命令,但 python 显示以下错误:

文件“C:\Python34\lib\ssl.py”,第 810 行,do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:600)

我的问题如下:

1.) 代码的正确格式是什么?只是返回网址中“code=”之后的所有字符?

2.) 还有什么可能导致此错误?我按照其他地方的建议安装了 certifi 2015.04.28 ,但这并没有解决问题。

3.) 还有其他修复建议吗?

代码如下

from oauth2client.client import flow_from_clientsecrets

from selenium import webdriver
from selenium.webdriver.common.keys import Keys



flow = flow_from_clientsecrets('C:\Python34\client_secrets.json',
                               scope='https://www.googleapis.com/auth/drive',
                               redirect_uri='https://www.samtec.com)
auth_uri = flow.step1_get_authorize_url()



#open firefox, send auth_uri to the interwebs
driver = webdriver.Firefox()
driver.get(auth_uri)

name=driver.find_element_by_name("Email")
name.send_keys("******")
name.send_keys(Keys.RETURN)

#wait 10 seconds for the page to load before proceeding
#driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
driver.implicitly_wait(10)
passw=driver.find_element_by_name("Passwd")
passw.send_keys("*******")
passw.send_keys(Keys.RETURN)


#wait for page to load, approve access token
driver.implicitly_wait(10)
allow=driver.find_element_by_id("submit_approve_access")
allow.send_keys(Keys.RETURN)

#get the URL returned to the browser, get the returned code
returnedURL=driver.current_url
if "=" in returnedURL:
    param, code = returnedURL.split("=",1)

##remove white space
code=code.strip()

##obtain he OAuth2 object/tokens
credentials = flow.step2_exchange(code) ##error occurs on this line

使用 python 3.4.3

谢谢

4

0 回答 0