Object 'user' has no atribute 'create' – Django

Question:

I have a question about an error that I am getting. I have a query that I am trying to send based on the Synapse Api for my project. I am currently trying to senda request taht creates a new user with the API. Every time I try to to send the request, I get a message that the User object doesnt have a create. Here is the error.

AttributeError at /setup_profile/
type object 'User' has no attribute 'create'
Request Method: POST
Request URL:    http://127.0.0.1:8000/setup_profile/
Django Version: 1.8.6
Exception Type: AttributeError
Exception Value:    
type object 'User' has no attribute 'create'
Exception Location: C:UsersOmarJandaliDesktopopentabopentabtabviews.py in createUserSynapse, line 1104

Here is the current code that I have which will create the request to create a new user.

def createUserSynapse(request):
    args = {
        'email': '[email protected]',
        'phone_number': '555-555-5555',
        'legal_name': 'Hello McHello',
        'note': ':)',  # optional
        'supp_id': '123abc',  # optional
        'is_business': True,
        'cip_tag': 1
    }

    user = User.create(client, **args)
    print(user)

Now i do know that with a normal query set, I have the object in the following format

User.objects.create(client, **args)

but when i do that I get an error that says

two parameters are being passed and 1 is requires so I think there is to many variables being passed… I am not sure where the error is coming from…

here is the error that I get when I use the User.objects.create(client, ** args)

TypeError at /setup_profile/
create() takes 1 positional argument but 2 were given
Request Method: POST
Request URL:    http://127.0.0.1:8000/setup_profile/
Django Version: 1.8.6
Exception Type: TypeError
Exception Value:    
create() takes 1 positional argument but 2 were given
Exception Location: C:UsersOmarJandaliAppDataLocalProgramsPythonPython36libsite-packagesdjangodbmodelsmanager.py in manager_method, line 127

UPDATED

The client needs to be passed into the api call and it contains the following:

import os
from synapse_pay_rest import Client

args = {
    'client_id': 'client_id_...6YiBl',
    'client_secret': 'client_secret_...kC3IF',
    'fingerprint': '...dd48b',
    'ip_address': '127.0.0.1',
    'development_mode':True,
    'logging':False
}

client = Client(**args)

Also, here is a github link to the api samples that were created by the api developers.

https://github.com/synapsepay/SynapsePayRest-Python

the client has to be passed with the api call

Asked By: Omar Jandali

||

Answers:

Create method has only key word arguments. Rewrite your code to this:

User.objects.create(client=client, **args)

UPDATE

I just figured out that you are using third party package. So you need to import User class like this from synapse_pay_rest import User as SynapseUser and use SynapseUser in your code: SynapseUser.create(clients, **argss)

Answered By: neverwalkaloner
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.