client.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:zhihu-oauth 作者: 7sDream 项目源码 文件源码
def login_in_terminal(self, username=None, password=None,
                          use_getpass=True, captcha_filename=None):
        """
        ?????????????????????????

        ???? username ? password ?????????????

        ..  note:: ???????????????????

        :param str|unicode username: ???????
        :param str|unicode password: ???
        :param bool use_getpass: ?????????????????????????? True?
            ????????? Windows ??? IDE ?????????????getpass ???
            ????????? False ??????new in version > 0.0.16?
        :param str|unicode captcha_filename: ??????????
            ?????????????????????????????
        :return: .. seealso:: :meth:`.login`
        """
        print('----- Zhihu OAuth Login -----')
        print('?????????????????? +86')

        username = username or input('email/phone: ')

        if password is None:
            if use_getpass:
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore', getpass.GetPassWarning)
                    password = getpass.getpass(str('password: '))
            else:
                password = input('password: ')

        try:
            success, reason = self.login(username, password)
        except NeedCaptchaException:
            print('Need for a captcha, getting it......')
            captcha_image = self.get_captcha()
            captcha_filename = captcha_filename or DEFAULT_CAPTCHA_FILENAME
            with open(captcha_filename, 'wb') as f:
                f.write(captcha_image)
            print('Please open {0} for captcha'.format(
                os.path.abspath(captcha_filename)))
            captcha = input('captcha: ')
            os.remove(os.path.abspath(captcha_filename))
            success, reason = self.login(username, password, captcha)

        if success:
            print('Login success.')
        else:
            print('Login failed, reason: {}'.format(reason))

        return success, reason
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号