bowenpay / wechat-spider

微信公众号爬虫
http://wechatspider.0fenbei.com/
3.15k stars 1k forks source link

Forbidden (CSRF token missing or incorrect.): /wechat/add/ #47

Open Huangkk2016 opened 7 years ago

Huangkk2016 commented 7 years ago

跑downloader.py那个脚本的时候会显示:

DEBUG 2017-03-26 13:41:36,828 init 16456 140440915134208 version=0.2.3 DEBUG 2017-03-26 13:41:36,829 init 16456 140440915134208 version=0.2.1

跑python bin/processor.py

^CTraceback (most recent call last): File "bin/processor.py", line 57, in processor.run() File "bin/processor.py", line 45, in run rsp = r.brpop(settings.CRAWLER_CONFIG["processor"]) File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 1183, in brpop return self.execute_command('BRPOP', *keys) File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 573, in execute_command return self.parse_response(connection, command_name, **options) File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 585, in parse_response response = connection.read_response() File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 577, in read_response response = self._parser.read_response() File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 238, in read_response response = self._buffer.readline() File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 168, in readline self._read_from_socket() File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 126, in _read_from_socket data = self._sock.recv(socket_read_size) KeyboardInterrupt

添加公众号的时候按添加会报下图的错误:

禁止访问 (403) CSRF验证失败. 相应中断. Help Reason given for failure: CSRF token missing or incorrect.

In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure: Your browser is accepting cookies. The view function passes a request to the template's render method. In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL. If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data. The form has a valid CSRF token. After logging in in another browser tab or hitting the back button after a login, you may need to reload the page with the form, because the token is rotated after a login. You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed. You can customize this page using the CSRF_FAILURE_VIEW setting.

不应该报csrf 问题啊

yijingping commented 7 years ago

你的django 版本是1.8吗?

Huangkk2016 commented 7 years ago

django 版本是:1.10.6,我目前是禁用掉 'django.middleware.csrf.CsrfViewMiddleware', 把添加报错解决了

但是点击关键词,最新文章和可用项目都是报下面的错误:

TypeError at /wechat/keywords/ render_to_response() got an unexpected keyword argument 'context_instance' Request Method: GET Request URL: http://localhost:8001/wechat/keywords/ Django Version: 1.10.6 Exception Type: TypeError Exception Value:
render_to_response() got an unexpected keyword argument 'context_instance' Exception Location: /home/kun/wechat-spider/wechat/views.py in keywords_list, line 324 Python Executable: /usr/bin/python Python Version: 2.7.11 Python Path:
['/home/kun/wechat-spider', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/pip-9.0.1-py2.7.egg', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0'] Server time: 星期日, 26 三月 2017 15:29:04 +0800

我还有疑问,我添加微信公众号了,我怎么知道他有没有爬啊?感觉没有在爬,点击已爬取文章都是报上面的错误

yijingping commented 7 years ago

还是django版本的问题吧。 如果想要知道是否在爬,看 bin/scheduler.pybin/downloader.py 打印的内容