python - SynapsePay & Django conflicting instances of User issue -
my name omar. working on django project using synapsepay api monetary transactions. getting issue have 2 instances of same object(user). django uses 'user' object when new users created within django application. synapse uses 'user' objects when new user created within api. when try use synapse api, starting conflicting uses of same variable.
in import statements, when imported user synapse api, saved instance of user synapseuser , using interact application.
there parts of api not controllable me use 'user' object within api , grabbing wrong object or trying grab key doesnt exist in key being passed.
here code have , error trying get...
the following code grab forms content , test bank authroization api..
here link api github samples.md file
here views.py file:
import os synapse_pay_rest import client synapse_pay_rest import user synapseuser synapse_pay_rest.models.nodes import achusnode def linkbanklogin(request, form): currentuser = loggedinuser(request) cd = form.cleaned_data bank_name = cd['bank'] username = cd['username'] password = cd['password'] required = { 'bank_name':'wellsfargo', 'username':'omarjandali', 'password':'123123asd' } ach_us = achusnode.create_via_bank_login(synapseuser, **required) ach_us.mfa_verified
here error getting when user submits linking account form:
attributeerror @ /link_account/ type object 'user' has no attribute 'client' request method: post request url: http://127.0.0.1:8000/link_account/ django version: 1.11.5 exception type: attributeerror exception value: type object 'user' has no attribute 'client' exception location: /library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/synapse_pay_rest/models/nodes/ach_us_node.py in create_via_bank_login, line 39
create_via_bank_login internal method created within api , not can change. how can grab synapseuser
** update **
the following code used user id:
user = user.by_id(client, '...4dc1')
so can this:
synapseuser = synapseuser.by_id(client, '...4dc1')
because code added above worked in returning created users information
and instead of:
ach_us = achusnode.create_via_bank_login(synapseuser, **required)
i can use:
ach_us = achusnode.create_via_bank_login(synapseuser, **required)
** continued update **
i have following code perform wanted integrate:
def searchusersynapse(request): currentuser = loggedinuser(request) currentprofile = profile.objects.get(user = currentuser) synapse_id = currentprofile.synapse_id user = synapseuser.by_id(clients, str(synapse_id)) response = user.json print(response) return user def linkbanklogin(request, form): currentuser = loggedinuser(request) cd = form.cleaned_data bank_name = cd['bank'] username = cd['username'] password = cd['password'] required = { 'bank_name':'wellsfargo', 'username':'omarjandali', 'password':'123123asd' } response = searchusersynapse(request) ach_us = achusnode.create_via_bank_login(response, **required) ach_us.mfa_verified
and new error message following:
badrequesterror @ /link_account/ no exception message supplied request method: post request url: http://127.0.0.1:8000/link_account/ django version: 1.11.5 exception type: badrequesterror exception location: /library/frameworks/python.framework/versions/3.6/lib/python3.6/site- packages/synapse_pay_rest/http_client.py in parse_response, line 86
how can find out request had error??
you need pass instance of class synapseuser
, not class itself.
the line:
ach_us = achusnode.create_via_bank_login(synapseuser, **required)
should be:
ach_us = achusnode.create_via_bank_login(user, **required)
where user
of type synapseuser
so need fetch synapseuser
django user
beforehand:
user = synapseuser.by_id(client, synapse_user_id)
you need create method synapse_user_id
django user (in case currentuser
)
i recommend creating userprofile
class one-to-one relationship user
can store , other information.
see this post example of how set up.
Comments
Post a Comment