2013-01-10 34 views
3

我有一個簡單的Python腳本發送Gearman的任務:蟒蛇 - 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() 

我不知道我是什麼在這裏做錯了,齒輪工服務器不斷給我以下錯誤:

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

你可以發佈完整的追溯,所以我們可以知道你的錯誤是哪一行? – mgilson

回答

3

我最好的猜測是,功能queue_feed應該return東西:例如:

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

如果不明確地從Python函數返回的東西,它含蓄地返回None這就是爲什麼Python是抱怨越來越NoneType

+0

這就是問題所在,我仍然是一個Python的新手:) – Joe

+0

接受延遲5分鐘後我會接受你的答案 – Joe

+0

好的答案 - 我有一個與Gearman類似的問題,通過做一個返回'somestring' – RichVel