def _prompt_user_for_token(url, token_type):
"""Get Token from user
:param url: url for user to go to
:type url: str
:param token_type: type of token to be received
:type token_type: str
:returns: token show to user by browser
:rtype: str
"""
msg = textwrap.dedent("""\
If your browser didn't open, please go to the following link:
{url}
Enter {token_type}: """)
msg = msg.lstrip().format(url=url, token_type=token_type)
try:
webbrowser.open_new_tab(url)
except webbrowser.Error as exc:
logger.warning(
'Exception occurred while calling webbrowser.open(%r): %s',
url, exc,
)
pass
sys.stderr.write(msg)
sys.stderr.flush()
token = sys.stdin.readline().strip()
return token
评论列表
文章目录