# Python: Unable to get user information by Management API V2 by user ID

**URL:** <https://community.auth0.com/t/python-unable-to-get-user-information-by-management-api-v2-by-user-id/90743>\
**Category:** Get Help\
**Tags:** python, management-api, auth0\
**Created:** [September 15, 2022, 10:03pm UTC](https://community.auth0.com/t/python-unable-to-get-user-information-by-management-api-v2-by-user-id/90743 "2022-09-15T22:03:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![somethingwitty](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/somethingwitty/32/14596_2.png) [@somethingwitty](https://community.auth0.com/u/somethingwitty)\
**Post date:** [September 15, 2022, 10:03pm UTC](https://community.auth0.com/t/python-unable-to-get-user-information-by-management-api-v2-by-user-id/90743/1 "2022-09-15T22:03:18Z")

</div>

I get the access token by:

```auto
conn = http.client.HTTPSConnection("{env.get("AUTH0_DOMAIN")}")

payload = "{\"client_id\":\"id\",\"client_secret\":\"secret\",\"audience\":\"https://{env.get("AUTH0_DOMAIN")}/api/v2/\",\"grant_type\":\"client_credentials\"}"

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

conn.request("POST", "/oauth/token", payload, headers)

res = conn.getresponse()
data = res.read()
token_json = data.decode('utf-8').replace("'", '"')
token = json.loads(token_json)
AUTH0_ACCESS_TOKEN = token["access_token"]

```

which is successful and I get the management API access token.

The problem arises when I try to get user information during callback:

```auto
@app.route("/callback", methods=["GET", "POST"])
def callback():
    token = oauth.auth0.authorize_access_token()
    session["user"] = token
    id = session['user']['userinfo']['sub']

    conn = http.client.HTTPConnection("{env.get("AUTH0_DOMAIN")}")
    headers = { 'authorization': "Bearer {}".format(AUTH0_ACCESS_TOKEN)}

    conn.request("GET", f"/api/v2/users/{id}", headers=headers)

    res = conn.getresponse()
    data = res.read()
    user_json = data.decode('utf-8').replace("'", '"')
    user_data = json.loads(user_json)

```

The error occurs with the last line. `json.loads` yields an error: `json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)`

When I checked the `user_json`, I find that it is empty meaning I didn’t get a response from the Management API.

What am I doing wrong? Is there a formatting mistake? Am I not using the right user\_id? For ID, I tried both `session['user']['userinfo']['sub']` and `session['user']['userinfo']['sub'].split('|', 1)[1]` to exclude the prefix in the ID but still getting the same error.

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [September 16, 2022, 12:26am UTC](https://community.auth0.com/t/python-unable-to-get-user-information-by-management-api-v2-by-user-id/90743/3 "2022-09-16T00:26:02Z")

</div>

Hi @somethingwitty ,

Welcome to the Auth0 Community!

Could you try the following scripts and see if you can get the user information?

```auto
@app.route("/callback", methods=["GET", "POST"])
def callback():
    token = oauth.auth0.authorize_access_token()
    session["user"] = token
    id = session['user']['userinfo']['sub']

    conn = http.client.HTTPConnection("{env.get("AUTH0_DOMAIN")}")
     
    payload = '';

    headers = { 'authorization': "Bearer {}".format(AUTH0_ACCESS_TOKEN)}

    conn.request("GET", "/api/v2/users/{id}", payload, headers)

    res = conn.getresponse()
    data = res.read()
    user_json = data.decode('utf-8').replace("'", '"')
    user_data = json.loads(user_json)

```

Thanks!

---

<div class="post-metadata">

**Author:** ![somethingwitty](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/somethingwitty/32/14596_2.png) [@somethingwitty](https://community.auth0.com/u/somethingwitty)\
**Post date:** [September 16, 2022, 5:07pm UTC](https://community.auth0.com/t/python-unable-to-get-user-information-by-management-api-v2-by-user-id/90743/4 "2022-09-16T17:07:34Z")

</div>

Hi, I’m still getting the same error `json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)` with your script. `user_json` still is blank

---

<div class="post-metadata">

**Author:** ![somethingwitty](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/somethingwitty/32/14596_2.png) [@somethingwitty](https://community.auth0.com/u/somethingwitty)\
**Post date:** [September 20, 2022, 6:25pm UTC](https://community.auth0.com/t/python-unable-to-get-user-information-by-management-api-v2-by-user-id/90743/5 "2022-09-20T18:25:37Z")

</div>

I think I figured out what was wrong with getting user information in callback.

This  
`conn = http.client.HTTPConnection("{env.get("AUTH0_DOMAIN")}")`

should be instead  
`conn = http.client.HTTPSConnection("{env.get("AUTH0_DOMAIN")}")`

The quickstart guide in Auth0’s console for a Machine to Machine app said to use HTTPConnection so that might need to be fixed.

---

<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:** [October 4, 2022, 6:26pm UTC](https://community.auth0.com/t/python-unable-to-get-user-information-by-management-api-v2-by-user-id/90743/6 "2022-10-04T18:26:13Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
