当我尝试运行下面的代码时,
from oauth2client import tools
creds = tools.run_flow(flow, store, flags)
当我关闭网络浏览器而不登录时,以下是在终端上以这种方式出现和冻结的屏幕,页面不断加载并且在我的 django 网页中不显示任何内容。
无论如何我可以为此使用例外吗?就像如果用户没有登录那么它就不会启动这个过程。?
请在下面找到我的全部代码,
from __future__ import print_function
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import argparse
class Drive:
# If modifying these scopes, delete the file token.json.
SCOPES = 'https://www.googleapis.com/auth/drive.file'
def __init__(self):
try:
flags = tools.argparser.parse_args([])
except ImportError:
flags = None
store = file.Storage('token.json')
self.creds = store.get()
if not self.creds or self.creds.invalid:
flow = client.flow_from_clientsecrets(settings.GOOGLE_OAUTH2_CLIENT_SECRETS_JSON, self.SCOPES)
try:
if flags:
self.creds = tools.run_flow(flow, store, flags)
print("self.creds",self.creds)
except:
pass
self.service = build('drive', 'v3', http=self.creds.authorize(Http()))