How to implement Auth0's Direct Password Change feature using Management API in Django?

Hi there,

I have a Django App, and I am trying to use Auth0 for my Django App’s authentication. I have successfully integrated Login and Logout using social-auth-app-django library. But I am facing a lot of hurdles in implementing Auth0’s Management API to use direct password change feature in Django? I tried to follow what this Auth0’s official documentation’s link says to implement Auth0’s Management API for direct password change feature, but it is throwing Error Code 500, and I am not understanding what I did wrong.

The link shows the following example to implement Auth0 Management API for firect password change feature in Django:

import http.client

conn = http.client.HTTPSConnection("")

payload = "{\"password\": \"NEW_PASSWORD\",\"connection\": \"CONNECTION_NAME\"}"

headers = { 'content-type': "application/json" }

conn.request("PATCH", "/dev-9fj5kydc.us.auth0.com/api/v2/users/USER_ID", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

And my implementation for the same is:

import http.client

user = self.request.user

NEW_PASSWORD = form.cleaned_data["new_password1"]
CONNECTION_NAME = settings.AUTH0_CONNECTION_NAME
DOMAIN = settings.SOCIAL_AUTH_AUTH0_DOMAIN
USER_ID = user.auth0_id
URL = f"/{DOMAIN}/api/v2/users/{USER_ID}"

conn = http.client.HTTPSConnection("")

payload = f"{{\"password\": \"{NEW_PASSWORD}\",\"connection\": \"{CONNECTION_NAME}\"}}" ### Here I am using 'Username-Password-Authentication' as Connection Name

headers = { 'content-type': "application/json" }

conn.request("PATCH", URL, payload, headers)

res = conn.getresponse()
data = res.read()

I have double checked that everything is fine by printing values in console and all variables hold correct values. Can someone help me and tell what wrong I am doing?