我在 Jetson Xavier 中有无头软件。我正在使用 Gmail API 发送邮件。我的代码在笔记本电脑中正常工作,但是在 Jetson 中禁用了 GUI 服务,无法打开浏览器。因此,当我尝试在 Jetson 中使用 Gmail API 时,身份验证失败。
我已将经过身份验证的“token.pickle”从笔记本电脑复制到 Jetson。它可以在短时间内正常工作。然后,它想要再次进行身份验证。
我该如何解决这个问题?如何阻止浏览器在 Jetson 中打开进行身份验证?
谢谢。
这部分代码用于身份验证:
class EmailSender:
def __init__(self):
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/gmail.compose']
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
creds_dir = os.path.dirname(os.path.abspath(__file__)) + '/credentials.json'
flow = InstalledAppFlow.from_client_secrets_file(
creds_dir, SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
self.service = build('gmail', 'v1', credentials=creds)