Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 类型错误:';instancemethod';对象没有属性'__获取项目';芹菜_Python_Django_Celery_Python Requests - Fatal编程技术网

Python 类型错误:';instancemethod';对象没有属性'__获取项目';芹菜

Python 类型错误:';instancemethod';对象没有属性'__获取项目';芹菜,python,django,celery,python-requests,Python,Django,Celery,Python Requests,我使用的是Django==1.7.1,Django芹菜==3.1.16。 我已经按照指南设置了芹菜,并且能够运行一个示例任务。现在,我正在尝试使用requests.post提供的响应,但我不知道如何做到这一点。当我将此响应传递给另一个函数并尝试进行简单打印时,我得到了标题中提到的TypeError 内部app/tasks.py: from .helpers.handler import another_function @shared_task def gcm_send(ids, msg):

我使用的是Django==1.7.1,Django芹菜==3.1.16。

我已经按照指南设置了芹菜,并且能够运行一个示例任务。现在,我正在尝试使用requests.post提供的响应,但我不知道如何做到这一点。当我将此响应传递给另一个函数并尝试进行简单打印时,我得到了标题中提到的TypeError

内部app/tasks.py:

from .helpers.handler import another_function

@shared_task
def gcm_send(ids, msg):
    GCM_URL = "https://android.googleapis.com/gcm/send"
    API_KEY = "app_api_key"
    headers = {'content-type': 'application/json', "authorization": "key=" + API_KEY}
    json_data = make_json(ids, msg)
    r = requests.post(GCM_URL, data=json_data, headers=headers)
    another_function(ids, r.json())
在views.py中:

def gcm_dispatcher(request, regid, msg):
    gcm_send.delay(regid, msg) 
    return HttpResponse("Ok")

def another_function(ids, message):
    print message, type(message)
日志:

是一个
请求.响应
实例上的方法,您需要调用它:

another_function(ids, r.json())

感谢您指出错误,但尽管更正了,我还是得到了相同的错误。@tilaprimera错误发生在
gcmhandles.py
脚本中,您能分享其中的内容吗?谢谢尽管如此,我很确定它仍然与
json
vs
json()
有关。在第122行中,只有一个打印函数。这是第一行代码,它抛出了错误。嘿,我必须重新启动芹菜和服务器才能让它工作。错误现在消失了。@tilaprimera太棒了!因此,错误就出现在这个
json
vs
json()
案例中,对吗?谢谢。如果删除gcmhandlers.py中的第122行,此错误是否仍然存在?
121def another_function(regids, msg):
122    print msg, type(msg)
another_function(ids, r.json())