【发布时间】:2018-02-15 14:36:40
【问题描述】:
我有一个关于我遇到的错误的问题。我有一个要根据 Synapse Api 为我的项目发送的查询。我目前正在尝试发送请求以使用 API 创建一个新用户。每次我尝试发送请求时,都会收到一条消息,指出用户对象没有创建。这是错误。
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:\Users\OmarJandali\Desktop\opentab\opentab\tab\views.py in createUserSynapse, line 1104
这是我拥有的当前代码,它将创建创建新用户的请求。
def createUserSynapse(request):
args = {
'email': 'hello@synapsepay.com',
'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)
现在我知道,使用普通查询集,我的对象格式如下
User.objects.create(client, **args)
但是当我这样做时,我得到一个错误,上面写着
两个参数被传递,1 是必需的,所以我认为有很多变量被传递......我不确定错误来自哪里......
这是我在使用 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:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\manager.py in manager_method, line 127
更新
客户端需要传入api调用,它包含以下内容:
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)
另外,这里是 api 开发人员创建的 api 示例的 github 链接。
https://github.com/synapsepay/SynapsePayRest-Python
客户端必须通过 api 调用传递
【问题讨论】: