Object 'user' has no atribute 'create' - Django - python

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:\Users\OmarJandali\Desktop\opentab\opentab\tab\views.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': '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)
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:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\manager.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

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)

Related

Zeep got an unexpected keyword argument in operation

I'm trying to send a request to a WSDL WebServices. According to documentation, the requests must be formatted in XML.
I'm using Python and Zeep module. The operation a want to use is called 'Consulta' and parameters are called 'Comercio' and 'NumPedido' (first one is numeric type and second is alphanumeric).
The code I've tried is the following:
from zeep import Client, Settings
settings = Settings(strict=False, xml_huge_tree=True)
client = Client('https://testws.punto-web.com/wcfadproc/srvproceso.svc?wsdl', settings=settings)
request_data = { 'Comercio': '8004749', 'NumPedido': '7030510'}
client.service.Consulta_Marca(**request_data)
But this gives me error TypeError: {http://tempuri.org/}Consulta_Marca() got an unexpected keyword argument 'NumPedido'. Signature: `xml: xsd:string`
Can anyone give me some advice about fixing this? Because seems that the operation is correct, but do not why the parameters are bad.
EDIT:
I've tried this little new code
from zeep import Client, xsd, Settings
settings = Settings(strict=False, xml_huge_tree=True)
client = Client('https://testws.punto-web.com/wcfadproc/srvproceso.svc?wsdl', settings = settings)
parameters = xsd.Element(
'Consulta',
xsd.ComplexType([
xsd.Element(
'Comercio', xsd.Integer()
),
xsd.Element(
'NumPedido', xsd.String()
)
])
)
parameters_values = parameters( Comercio=8004749, NumPedido='7030510')
operation = client.service.Consulta_Marca(parameters_values)
operation
This gives me another error
The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'Consulta_Marca'. End element 'xml' from namespace 'http://tempuri.org/' expected. Found element 'Comercio' from namespace ''. Line 2, position 465
But think I'm closer because if I execute
client.service.Consulta_Marca(parameters), I get a valid response, but with null values because no parameters values were passed.
Please some help!

JSON RPC Returns 'Invalid API parameter' upon request in python

I'm trying to create my own jsonrpc client for a project, using python and requests. After an hour of searching online, Most errors are to do with people executing a get rather than a post or people getting a different error. According the the JSONRPC Spec (Found Here http://www.jsonrpc.org/specification) It should work. Any help would be most grateful. Thanks Sam.
Requests & Code Below:
Post Request Body:
{"method": "GudMethod", "params": {"ur": "HELLO"}, "jsonrpc": "2.0", "id": 1}
Request Response:
{
"jsonrpc": "2.0",
"result": {
"method": "GudMethod",
"success": false,
"error": "Invalid API parameter [jsonrpc] must be 2.0 [\"GudMethod\"]",
"extra": [],
"metrics": {
"st": "2018-05-24 22:16:37",
"sspt": 0.0006299018859863281
}
},
"id": null
}
Codes:
import json
import requests
class Client():
def __init__(self,url):
self.url = url
self.id = 0
def request(self,method,prms):
rq = Request(self,method,prms)
return rq
class Request():
def __init__(self,client,method,prms):
self.client = client
self.method = method
self.prms = prms
self.rq = None
def buildRequest(self):
self.client.id = self.client.id + 1
url = self.client.url + "?method={}".format(self.method)
jb = {}
jb["jsonrpc"] = "2.0"
jb["method"] = self.method
jb["params"] = self.prms
jb["id"] = self.client.id
body = json.dumps(jb)
return url,body
def execute(self):
url , body = self.buildRequest()
self.rq = requests.post(url,data=body)
print(body)
print(self.rq.text)
Also, dont ask me to use a ready made one. I was told that already, but due to where the project will be used, I can't install any librarys. Luckily requests will be installed, that would be painful otherwise
Your client's request looks fine.
The server must be parsing your request incorrectly, assigning the value GudMethod to the name jsonrpc.
Not only is the server parsing your request incorrectly, but the response also is not valid according to the JSON-RPC specification:
1) There should be no result field:
result
This member is REQUIRED on success.
This member MUST NOT exist if there was an error invoking the method.
The value of this member is determined by the method invoked on the Server.
2) There should be a top-level error field:
error
This member is REQUIRED on error.
This member MUST NOT exist if there was no error triggered during invocation.
The value for this member MUST be an Object as defined in section 5.1.
3) The error field should be a JSON Object with the following fields:
code
A Number that indicates the error type that occurred.
This MUST be an integer.
message
A String providing a short description of the error.
The message SHOULD be limited to a concise single sentence.
data
A Primitive or Structured value that contains additional information about the error.
This may be omitted.
The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).
As the server erroneously believes the jsonrpc field is not equal to 2.0, the error code field should be -32600 and the message field Invalid Request indicating
The JSON sent is not a valid Request object.

How to use aqua.io API (for ICD-10 description to code)

I am doing a project for medical data mining ,and using a python api call Aqua.io ,the goal is to search for ICD code by their description.
The tutorial is not so clear for me,especially the parameters call 'client_options' and 'option'.
Tutorial
The description of client option are below:
Client Options
The following options are available while instantiating a client:
base: Base url for the api
user_agent: Default user-agent for all requests
headers: Default headers for all requests
request_type: Default format of the request body
client = aqua_io.Client({ 'client_id': '09a8b7', 'client_secret': '1a2b3' }, client_options)
I am not sure how to set this four parameters , are they all necessary?
I have try this way and came out an error:
TypeError: request() got an unexpected keyword argument 'request_type'
client = aqua_io.Client({ 'client_id': '****','client_secret': '***' },
{'base':'https://aqua.io','user_agent': '**', 'headers': 'XHTML', 'request_type': 'JSON'})
And if I only put parameter 'base' , it works.
client = aqua_io.Client({ 'client_id': '****','client_secret': '***' },{'base':'https://aqua.io'})
Similar question on parameter call method option,description is below:
Method Options
The following options are available while calling a method of an api:
headers: Headers for the request
query: Query parameters for the url
body: Body of the request
request_type: Format of the request body
When I run code like this, it came out an error:
TypeError: request() got an unexpected keyword argument 'request_type'
icd9 = client.icd9()
response = icd9.single_code("066-4",{'request_type':'json'})
Did anyone have experience of using this api ? Thanks !

Key Error = client_id -- django

I have an api that i am using for a project that I am working on. I am getting a key errror for the client Id that I have to pass in order ot call the api. THe api that i am using is Synapse. If anyone knows what is cuasing the error or how I can fix this key error, it would be a lit of help... Here is the full error.
KeyError at /
'client_id_...6YiBl'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.6
Exception Type: KeyError
Exception Value:
'client_id_...YiBl'
Exception Location: C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\os.py in __getitem__, line 669
Python Executable: C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\python.exe
Python Version: 3.6.1
Python Path:
['C:\\Users\\OmarJandali\\Desktop\\opentab\\opentab',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\lib',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages']
here is the code:
import os
from synapse_pay_rest import Client
args = {
'client_id': os.environ['client_id_...YiBl'],
'client_secret': os.environ['client_secret_...C3IF'],
'fingerprint': '599378e9a63ec2002d7dd48b',
'ip_address': '127.0.0.1',
'development_mode':True,
'logging':False
}
client = Client(**args)
Your code looks like it should be using the keys directly, whereas you're trying to access environment variables.
Basically, don't try to access these values via os.environ(), as it will make your application search for an environment variable named client_id_...YiBl.
from synapse_pay_rest import Client
args = {
'client_id': 'client_id_...YiBl',
'client_secret':'client_secret_...C3IF',
'fingerprint': '599378e9a63ec2002d7dd48b',
'ip_address': '127.0.0.1',
'development_mode':True,
'logging':False
}
client = Client(**args)

Django Post URL from Browser

I'm running through the Django tutorials, and I want to figure out how to post changes to a model from the Browser. Here's the URL:
url(r'^(?P<person_id>\d+)/updatePerson/$', views.updatePerson, name='updatePerson')
)
Here's the view:
def updatePerson(request, person_id):
p = get_object_or_404(Person, pk=person_id)
# try:
# user = p.get(pk=request.POST['name'])
# except (KeyError, Person.DoesNotExist):
# Redisplay the poll voting form.
# return render(request, 'maps/detail.html', {
# 'person': p,
# 'error_message': "This person does not exist",
# })
#else:
p.lat = request.POST['lat']
p.lon = request.POST['lon']
p.task = request.POST['task']
p.save()
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('maps:detail', args=(p.id,)))
The url I try is:
<serveraddress>/maps/1/updatePerson/?lat=20&lon=20&task=hangOut
I get this error:
MultiValueDictKeyError at /maps/1/updatePerson/
"Key 'lat' not found in <QueryDict: {}>"
Request Method: GET
Request URL: <serveraddress>/maps/1/updatePerson/?lat=20
Django Version: 1.5.2
Exception Type: MultiValueDictKeyError
Exception Value:
"Key 'lat' not found in <QueryDict: {}>"
Exception Location: D:\Python\lib\site-packages\django\utils\datastructures.py in __getitem__, line 295
Python Executable: D:\Python\python.exe
Python Version: 2.7.5
Python Path:
['C:\\GXM_LABS\\gxm_maps',
'D:\\Python\\lib\\site-packages\\setuptools-1.1.3-py2.7.egg',
'D:\\Python\\lib\\site-packages\\django_evolution-0.6.9-py2.7.egg',
'D:\\Python\\lib\\site-packages\\south-0.8.2-py2.7.egg',
'C:\\Windows\\system32\\python27.zip',
'D:\\Python\\DLLs',
'D:\\Python\\lib',
'D:\\Python\\lib\\plat-win',
'D:\\Python\\lib\\lib-tk',
'D:\\Python',
'D:\\Python\\lib\\site-packages']
Server time: Sat, 7 Sep 2013 16:42:14 -0400
Should I be doing a regex in my url definiition to catch the values? Or am I approaching this incorectly? I'm working along with the tutorials but modifying them to suit some work I'm doing on the side. I don't really want a form which users input, as in the long run I'll be posting this data from remote locations (Smartphones), and so a webpage which acually has the ability to submit this data is less interesting to me than the ability to post these changes directly.
You should read your query parameters from request.GET instead of a request.POST since you are making a GET request (see Request Method: GET on your error page).
FYI, there is also request.REQUEST dictionary available:
For convenience, a dictionary-like object that searches POST first,
then GET. Inspired by PHP’s $_REQUEST.
But, it's not a good practice to use it. Better be explicit.

Categories

Resources