【问题标题】:python - gearman - keep getting typeerrorpython - gearman - 不断收到类型错误
【发布时间】:2013-01-10 14:48:31
【问题描述】:

我有一个简单的 python 脚本来发送 gearman 任务:

客户:

        # "source" is a simple tuple
        client = GearmanClient(['localhost'])
        client.submit_job('queue_feed', simplejson.dumps(source))

服务器:

def queue_feed(work, job):
    source = simplejson.loads(job.data)
    print source

if __name__ == '__main__':
    if len(sys.argv) > 1:
        if sys.argv[1] == "spawn":
            worker = GearmanWorker(['localhost'])
            #nohup python /home/padsquad/apps/gearman_articles.py spawn &
            worker.register_task('queue_feed', queue_feed)
            print 'working...'
            worker.work()

我不确定我在这里做错了什么,gearman 服务器一直给我以下错误:

TypeError: Expecting byte string, got <type 'NoneType'>

【问题讨论】:

  • 您能否发布完整的回溯,以便我们知道您在哪一行出现错误?

标签: python gearman


【解决方案1】:

我最好的猜测是函数 queue_feed 应该是 return 某事:例如:

def queue_feed(work, job):
    source = simplejson.loads(job.data)
    print source
    return source

如果您没有从 python 函数显式返回某些内容,它会隐式返回 None,这就是 python 抱怨获取 NoneType 的原因

【讨论】:

  • 这正是问题所在,我还是 python 的新手 :)
  • 接受延迟 5 分钟后我会接受你的回答
  • 好答案 - 我在 Gearman 遇到了类似的问题,通过执行 return 'somestring' 解决了
猜你喜欢
  • 2016-01-30
  • 1970-01-01
  • 2016-02-01
  • 2020-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多