Fails with HTTPError 400 Bad Request:
imports..
def main():
access_token = ""...
variables = ""...
base_url = "https://{domain}".format(domain=DOMAIN)
data_auth = parse.urlencode(
('client_id', CLIENT_ID),
('client_secret', CLIENT_SECRET),
('audience', AUDIENCE),
('grant_type', GRANT_TYPE),
('email', EMAIL),
('password', PASSWORD),
('connection', CONNECTION),
('email_verified', EMAIL_VERIFIED),
('verify_email', VERIFY_EMAIL),
('user_metadata', USER_METADATA)
]).encode("utf-8")
req = Request(base_url + "/oauth/token", data_auth)
try:
response = request.urlopen(req)
oauth = json.loads(response.read())
access_token = oauth'access_token']
print(access_token)
except error.HTTPError as e:
print('HTTPError = ' + str(e.code) + ' ' + str(e.reason))
except error.URLError as e:
print('URLError = ' + str(e.reason))
except Exception as e:
print('Generic Exception' + str(e))
data_user = bytes(parse.urlencode(
('audience', AUDIENCE),
('grant_type', GRANT_TYPE),
('email', EMAIL),
('password', PASSWORD),
('connection', CONNECTION),
('email_verified', EMAIL_VERIFIED),
('verify_email', VERIFY_EMAIL),
('user_metadata', USER_METADATA)
]).encode("utf-8"))
req = Request(base_url + "/dbconnections/signup", data_user)
req.add_header('Authorization', 'Bearer ' + access_token)
req.add_header('Content-Type', 'application/json')
try:
response = request.urlopen(req, data_user)
res = json.loads(response.read())
print(res)
except error.HTTPError as e:
print('HTTPError = ' + str(e.code) + ' ' + str(e.reason))
except error.URLError as e:
print('URLError = ' + str(e.reason))
except Exception as e:
print('Generic Exception' + str(e))
if __name__ == '__main__':
main()