I am new using Auth0 and I am facing difficulties to generate a token using the snippet available on
I can reproduce the token generation with curl, on command line, but I can’t take the same result with the Python snippet, which is copied bellow, with my attempts:
import httplib, urllib
from decouple import config
AUTH0_CLIENT_SECRET = config("AUTH0_CLIENT_SECRET")
# AUTH0_CLIENT_ID = config("AUTH0_CLIENT_ID")
# AUTH0_AUDIENCE = config("AUTH0_AUDIENCE")
AUTH0_AUDIENCE = config("AUTH0_CLIENT_ID")
AUTH0_API_IDENTIFIER = config("AUTH0_API_IDENTIFIER")
conn = httplib.HTTPSConnection("")
# payload = "grant_type=client_credentials&client_id=" + AUTH0_CLIENT_ID + "&client_secret=" + AUTH0_CLIENT_SECRET + "&audience=" + AUTH0_AUDIENCE
# payload = {"grant_type": "client_credentials", "client_id": AUTH0_CLIENT_ID, 'client_secret': AUTH0_CLIENT_SECRET, 'audience': AUTH0_AUDIENCE}
payload = urllib.urlencode({"grant_type": "client_credentials", "client_id": AUTH0_CLIENT_ID, 'client_secret': AUTH0_CLIENT_SECRET, 'audience': AUTH0_AUDIENCE})
headers = { 'Content-type': "application/x-www-form-urlencoded" }
conn.request("POST", "/my-app.us.auth0.com/oauth/token", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
return data
Am i missing something? My answers are one of the following (with different payload values bellow):
- socket.gaierror: [Errno -5] No address associated with hostname
- 401 Response
- gaierror: [Errno -2] Name or service not known
The error is always on line “conn.request(“POST”, “/my-app.us.auth0.com/oauth/token”, payload, headers)”.
The value for the “audience” key seems to be the https://my-app.us.auth0.com/api/v2/ despite the link above tells that it is the API_IDENTIFIER
My snippet is on Python 2, but I had already tried it on Python 3 as well with similar results. Thanks in advance.