Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

跑简单的用例都出错,不知道其他人有没遇到 #43

Open
zhangyiw opened this issue Aug 21, 2018 · 2 comments
Open

跑简单的用例都出错,不知道其他人有没遇到 #43

zhangyiw opened this issue Aug 21, 2018 · 2 comments

Comments

@zhangyiw
Copy link

其他情况zhihu.profile()调用后,输入账号密码也是报差不多的错误

$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

from zhihu import Account
account = Account()
account.login("yxxxxxxxxxx","pxxxxxx")
Traceback (most recent call last):
File "", line 1, in
File "/home/yiwu/.local/lib/python3.5/site-packages/zhihu/models/account.py", line 29, in login
return self._login_api(account, password)
File "/home/yiwu/.local/lib/python3.5/site-packages/zhihu/models/account.py", line 35, in _login_api
_xsrf, _dc0 = self._get_xsrf_dc0()
File "/home/yiwu/.local/lib/python3.5/site-packages/zhihu/models/base.py", line 84, in _get_xsrf_dc0
xsrf = response.cookies["_xsrf"]
File "/home/yiwu/.local/lib/python3.5/site-packages/requests/cookies.py", line 329, in getitem
return self._find_no_duplicates(name)
File "/home/yiwu/.local/lib/python3.5/site-packages/requests/cookies.py", line 400, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='_xsrf', domain=None, path=None"

@zhangyiw
Copy link
Author

def _get_xsrf_dc0(self, url=None):
    """
    获取某个URL页面下的xsrf
    :param url:
    :return: xsrf
    """
    response = self.get(url or URL.index())
    ### **xsrf = response.cookies["_xsrf"]**
    dc0 = response.cookies["d_c0"]
    return xsrf, dc0

File "/home/yiwu/.local/lib/python3.5/site-packages/requests/cookies.py", line 329, in getitem
return self._find_no_duplicates(name)
在_get_xsrf_dc0里面调用resp的cookies,获取_xsrf的值,底层requests的cookies却在no_duplicates上判断zhihu的cookie唯一时出错,在zhihu网站上,浏览器实测有两个_xsrf键和值,这是怎么回事。

@Freakwill
Copy link

@zhangyiw 我遇到的也是这个问题,解决了吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants