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

auth.py登录一直返回500错误 #71

Open
fero2004 opened this issue Jun 22, 2016 · 5 comments
Open

auth.py登录一直返回500错误 #71

fero2004 opened this issue Jun 22, 2016 · 5 comments

Comments

@fero2004
Copy link

`def search_xsrf():
"""

:rtype: object
"""
url = "http://www.zhihu.com/"
r = requests.get(url, verify=False)
if int(r.status_code) != 200:
    raise NetworkError(u"验证码请求失败")`

这里一直返回500,错误就是验证码请求失败

@tzhao0311
Copy link

请问楼上怎么加header,能说具体些吗?

@SUSHUO
Copy link

SUSHUO commented Jun 24, 2016

requests請求裏添加headers參數後錯誤變成正常的302跳轉請求,但是還是會提示驗證碼請求失敗啊

@Tassandar
Copy link

把request定义的时候加上一段,伪装成正常的浏览器就好了。

fake_head= { 
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',

'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',

'Connection':'keep-alive' 
}
requests.headers = fake_head

@yujunhui
Copy link

@SUSHUO
验证码请求失败的解决方法是一样的啊,在获取验证码那段代码的requests里面加多个headers

@simoncos
Copy link

不知道具體怎麼改的,可以嘗試用我的版本直接替代你的auth.py: https://github.com/simoncos/zhihu-analysis-python/blob/master/crawler/auth.py

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

6 participants