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.
I am sending the request from POSTMAN
I check by parameter user_type
Used Pipeline from 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
:
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
.
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'
. Obviously, it did not return this object but just returned None
, probably because of an i/o-error or an invalid argument.
Whatever function you use to get the request, I suggest checking, whether it works and what exactly it returns.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.