Code Monkey home page Code Monkey logo

Comments (7)

sherrywong1220 avatar sherrywong1220 commented on July 18, 2024

你好,源码中并未将登录后的cookies进行保存,也就是说没有保存登录状态,这样导致了每次身份验证时都未检测到登录,所以要不断重复登陆。我对登录验证功能进行了完善并pull requests了,这个bug应该已经被修复了,pr目前还未通过,您可以先clone我fork的项目试一下,https://github.com/sherrywong1220/zhihu-api

from zhihu-api.

lzjun567 avatar lzjun567 commented on July 18, 2024

有保存的呢

from zhihu-api.

lzjun567 avatar lzjun567 commented on July 18, 2024

这个问题我查了一下,你的pull request 还是不能解决重复登录的问题,因为在装饰器need_login执行后,用户输入帐号密码验证通过后,本地是有保存cookie的,但是当前获取用户信息的session并没有及时去加载cookie信息,所有需要用户重新登录。

我在你的pr基础之上修复了这个问题,并且对于所有请求如果不是返回的response.ok,那么直接以异常的方式抛出。

from zhihu-api.

sherrywong1220 avatar sherrywong1220 commented on July 18, 2024

棒棒的!我先前认为登录之后当前用户的session的cookie会自动update,所以就没有再次加载cookie。现在才反应过来session并不是一个全局变量,只有account类对象的session自动更新了,但其他类的session并没有自动更新。

from zhihu-api.

sherrywong1220 avatar sherrywong1220 commented on July 18, 2024

不过我还是认为当未检测到登录时,应该优先尝试加载本地cookie,而不是直接重新登录。否则会受到创建类实例的顺序影响。

>>> from zhihu import Zhihu
>>> zhihu = Zhihu()    # 此时本地无cookie,实例化对象的session中也无cookie

>>> from zhihu import Answer
>>> data = Answer(id=14005147).vote_down()    # 此时需要登录,登录后,本地有cookie

>>> zhihu.user(user_slug="xiaoxiaodouzi")    # 由于zhihu是在登录前实例化的对象,zhihu依然无登录信息,需要重新登录

from zhihu-api.

lzjun567 avatar lzjun567 commented on July 18, 2024

有道理

from zhihu-api.

ahwz001 avatar ahwz001 commented on July 18, 2024

经过安装最新的代码后,测试,本人所提的问题已解决!

至于各位所讨论的,我还在学习中,先继续学习全部代码吧。

感谢各位的辛勤工作!

from zhihu-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.