[英]'NoneType' object is not subscriptable. Where is the error? Used Django App with Pipeline
TypeError: 'NoneType' object is not subscriptable if request['user_type']=='driver' and not Driver.objects.filter(user_id = user.id): TypeError: 'NoneType' object is not subscriptable ```
def create_user_by_type(backend , user , request, response , *args, **kwargs):
if backend.name == 'facebook':
avatar = 'http://graph.facebook.com/%s/picture?type=large' % response['id']
if request['user_type'] == 'driver' and not Driver.objects.filter(user_id = user.id):
Driver.objects.create(user_id=user.id,avatar=avatar)
elif not Customer.objects.filter(user_id=user.id):
Customer.objects.create(user_id=user.id, avatar=avatar)
The error is most likely in request ['user_type'] == 'driver'
as it works if I remove this from the code.该错误很可能出现在请求['user_type'] == 'driver'
中,因为如果我从代码中删除它,它就会起作用。
I am sending the request from POSTMAN我正在发送来自 POSTMAN 的请求
I check by parameter user_type
我通过参数user_type
检查
Used Pipeline from https://python-social-auth.readthedocs.io/en/latest/pipeline.html使用来自https://python-social-auth.readthedocs.io/en/latest/pipeline.html的管道
If everything is correct, where can there be a mistake?如果一切都是正确的,哪里会有错误?
update create_user_by_type
:更新create_user_by_type
:
def create_user_by_type(backend, user, response, *args, **kwargs):
request = backend.strategy.request_data()
if backend.name == 'facebook':
avatar = 'http://graph.facebook.com/%s/picture?type=large' % response['id']
if request['user_type'] == 'driver' and not Driver.objects.filter(user_id = user.id):
Driver.objects.create(user_id=user.id,avatar=avatar)
elif not Customer.objects.filter(user_id=user.id):
Customer.objects.create(user_id=user.id, avatar=avatar)
The problem must lie in the object stored in variable request
.问题一定出在变量request
中存储的 object 上。
You get the value for request
in a function which should return a complex object, which is subscriptable and has a field called 'user type'
.您在 function 中获得request
的值,它应该返回一个复杂的 object,它是可下标的并且有一个名为'user type'
的字段。 Obviously, it did not return this object but just returned None
, probably because of an i/o-error or an invalid argument.显然,它没有返回这个 object 而是返回了None
,可能是因为 i/o 错误或无效参数。
Whatever function you use to get the request, I suggest checking, whether it works and what exactly it returns.无论您使用什么 function 来获取请求,我建议检查它是否有效以及它返回的确切内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.