【问题标题】:Feedparser - TypeError('a float is required',)Feedparser - TypeError('a float is required',)
【发布时间】:2015-05-06 20:00:46
【问题描述】:

我正在使用guvfeedparser 同时解析多个提要。以下是我的代码:

guv.monkey_patch(time=True, socket=True)

def parse_feed(_feed):  
    return feedparser.parse(_feed)

def main():
    urls = ["http://feeds.bbci.co.uk/news/rss.xml"]
    pool = guv.GreenPool()
    results = pool.starmap(parse_feed, zip(urls))
    for resp in results:
        print(str(resp)) 

但是,我得到以下输出:

{'bozo_exception': TypeError('a float is required',), 'bozo': 1, 'feed': {}, 'entries': []}

我在使用 Eventlet 时遇到了类似的问题,但在原生 Python 3 threading 库中没有。

【问题讨论】:

  • bozo_exception 错误由feedparser.parse() 返回。如果您在调用feedparser.parse 之前修改parse_feed 以打印_feed 的值,它是否收到了您认为收到的内容?
  • @larsks 谢谢。是的,它会打印列表中的 url。

标签: python lxml feedparser libuv


【解决方案1】:

我无法在本地安装 guv 模块,所以我无法逐字测试您的代码,但如果我改用 eventlet.greenpool.GreenPool 一切正常:

import feedparser
import eventlet.greenpool

def parse_feed(_feed):  
    print 'PARSE:', _feed
    return feedparser.parse(_feed)

def main():
    urls = ["http://feeds.bbci.co.uk/news/rss.xml"]
    pool = eventlet.greenpool.GreenPool()
    results = pool.starmap(parse_feed, zip(urls))
    for resp in results:
        print resp

main()

我还看到itertools.starmap() 的正确行为。您是否有可能看到某种暂时性错误?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-06
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2021-12-05
    • 2019-09-24
    • 1970-01-01
    相关资源
    最近更新 更多