Python中为feedparser设置超时时间避免堵塞
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接口自动化之使用token传入到header消息头中
这篇文章主要介绍了python接口自动化之使用token传入到header消息头中问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2023-08-08
最新评论