# Create User in Python Failes with HTTPError 400 Bad Request

**URL:** <https://community.auth0.com/t/create-user-in-python-failes-with-httperror-400-bad-request/8743>\
**Category:** Get Help\
**Tags:** python, create-user, api\
**Created:** [November 14, 2017, 5:09pm UTC](https://community.auth0.com/t/create-user-in-python-failes-with-httperror-400-bad-request/8743 "2017-11-14T17:09:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nottinhill](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nottinhill/32/6520_2.png) [@nottinhill](https://community.auth0.com/u/nottinhill)\
**Post date:** [November 14, 2017, 5:09pm UTC](https://community.auth0.com/t/create-user-in-python-failes-with-httperror-400-bad-request/8743/1 "2017-11-14T17:09:01Z")

</div>

Fails with HTTPError 400 Bad Request:

`imports..`  
`def main():`

```auto
    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()

```

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [November 14, 2017, 7:13pm UTC](https://community.auth0.com/t/create-user-in-python-failes-with-httperror-400-bad-request/8743/2 "2017-11-14T19:13:29Z")

</div>

The `/oauth/token` is not meant for user creation so not being able to create a user from that endpoint is the expected behavior.

In relation, to the `/dbconnections/signup` this will indeed allow to create/sign up a user (assuming the connection in question allows public signups). However, the payload you’re sending to that endpoint is incorrect so you should check the Authentication API explorer entry: [Authentication API Explorer](https://auth0.com/docs/api/authentication?http#signup)

Having said that, the payload you’re using seems to imply that you want to control if verification emails are sent or not (the payload contains `verify_email` parameter) so in that case you may not want to be using the public signup endpoint and instead create the user through the Auth0 Management API which would indeed support the `verify_email` parameter. See the following documentation for more info: [Auth0 Management API v2](https://auth0.com/docs/api/management/v2#!/Users/post_users)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:57am UTC](https://community.auth0.com/t/create-user-in-python-failes-with-httperror-400-bad-request/8743/3 "2018-03-02T05:57:24Z")

</div>


