I'm trying to build a script that auto creates users in Auth0's user API the emails i received off of another software, the print out of the email result looks like this:
{'update_id': '1570540963828', '59': '1570492800000', '16': 'xyz@xyz.com'}
{'update_id': '1570540932828', '59': '1570492800000', '16': 'abc@abc.com'}
However, when I tried to include this email result i got as an input into my http request, i get an error
{u'message': u'Invalid request payload JSON format', u'error': u'Bad Request', u'statusCode': 400}
this is what I have
for r in response:
#print r
email = str(r['16'])
data = '{"email":' + email +',connection":"Username-Password-Authentication","password":"blahblahblah"}'
res = requests.post(url="https://xxxxx.auth0.com/api/v2/users", data=data, headers=headers)
print res.json()
assuming i want all pw to be blahblahblah
any input appreciated,. i think it has somehting to do with the way I used those quotation marks.
edit: originally before i did this, i used a random email like sjd@shd.com inside the quotation marks and it worked, but now im trying to switch it to iterative email address list, its giving me that error
Check below snippet complete code, I have updated line data = {"email": email, "connection":"Username-Password-Authentication","password":"blahblahblah"}.
import requests
response = [{'update_id': '1570540963828', '59': '1570492800000', '16': 'xyz@xyz.com'},{'update_id': '1570540932828', '59': '1570492800000', '16': 'abc@abc.com'}]
for r in response:
headers = {}
email = str(r['16'])
data = {"email": email, "connection":"Username-Password-Authentication","password":"blahblahblah"} # updated line
res = requests.post(url="https://xxxxx.auth0.com/api/v2/users", data=data, headers=headers)
print(res.json())
i solved it. turns out json=data worked instead of data=data
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.