Python中为feedparser设置超时时间避免堵塞,pythonfeedparser


python有一个用于解析feed的模块:feedparser,feedparser解析各种feed是非常方便的,唯一比较恼火的是遇到一些badurl,经常会导致堵塞,因此需要为feedparser设置一个超时时间。

可是feedparser并没有提供这个功能,只好采用其他方法了,具体办法请参看feedparser项目的issue221。

其实也很简单,按照上面文档的说明

developers have had the ability to set a global timeout for over seven years by importing the socket library and setting the timeout in this way:

复制代码 代码如下:

import socket
socket.setdefaulttimeout(<timeout in floating seconds>)


python django下 cookies在什地方设置超时时间

不知道你是不是用set_cookie这个函数设置了cookie呢?
HttpResponse.set_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=None, httponly=True)
这个函数里面,max_age就是cookie的超时时间,是以秒为单位的。
也可以用expires设置绝对时间做为有效期,格式:"Wdy, DD-Mon-YY HH:MM:SS GMT",expires也可以是datetime.datetime的对象
 

新手教python安装feedparser-513出现问题,python27版本

在系统的命令行窗口里面输入命令,而不是在python命令行里面。比如windows系统就是“命令提示符”工具,Linux系统直接在终端敲命令就行。
 

相关内容

    暂无相关文章

评论关闭