# Call API Using Resource Owner Password Flow

**URL:** <https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751>\
**Category:** Get Help\
**Created:** [April 14, 2022, 11:49am UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751 "2022-04-14T11:49:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![giorgio.zorzi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giorgio.zorzi/32/36593_2.png) [@giorgio.zorzi](https://community.auth0.com/u/giorgio.zorzi)\
**Post date:** [April 14, 2022, 11:49am UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/1 "2022-04-14T11:49:42Z")

</div>

Hello,

I am trying to get the token from the API using the Password Flow following [this tutorial](https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-resource-owner-password-flow?_ga=2.24820730.1935995276.1649861577-1979681329.1649751416&_gl=1*oaj20y*rollup_ga*MTk3OTY4MTMyOS4xNjQ5NzUxNDE2*rollup_ga_F1G3E656YZ*MTY0OTkyOTM0NS40LjAuMTY0OTkyOTM0NS42MA..).

I am not able to successfully call the API and I receive

```auto
{"error":"access_denied","error_description":"Unauthorized"}

```

I am following the tutorial and I am not sure why this is not working. Any help on this?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 14, 2022, 3:12pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/3 "2022-04-14T15:12:02Z")

</div>

Hi @giorgio.zorzi,

Welcome to the Auth0 Community!

Can you please share the request (with any sensitive info removed) that is causing this error?

---

<div class="post-metadata">

**Author:** ![giorgio.zorzi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giorgio.zorzi/32/36593_2.png) [@giorgio.zorzi](https://community.auth0.com/u/giorgio.zorzi)\
**Post date:** [April 14, 2022, 5:55pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/4 "2022-04-14T17:55:28Z")

</div>

Hi @dan.woda,

Thank you for your reply!

I am using python following the script from the link. Here it is

```python
import http.client
import requests

url = "https://something.eu.auth0.com/oauth/token"
client_id = 'CLIENT_ID'
client_secret = 'CLIENT_SECRET'
username = 'test_user@email.com'
password = 'password'
api_identifier = '/api'
scope = "openid profile email"

conn = http.client.HTTPSConnection("")

headers = {'content-type': "application/x-www-form-urlencoded"}

data = {
    "grant_type": "password",
    "username": username,
    "password": password,
    "audience": api_identifier,
    "client_id": client_id,
    "client_secret": client_secret,
}

resp = requests.post(
    url=url,
    headers=headers,
    json=data,
)

print(resp.text)

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 14, 2022, 6:08pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/5 "2022-04-14T18:08:22Z")

</div>

Can you confirm that the password grant setting is turned on you application settings?

 ![image](https://global.discourse-cdn.com/auth0/original/3X/d/0/d081c51eef0a09d556a017ae0a7d473c7d1a8340.png)

And make sure the app is authorized to access the API you are declaring in the `audience` param.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/6/6/6616660f67881c81395c43534ae1aac1e6fdf65e.png)

---

<div class="post-metadata">

**Author:** ![giorgio.zorzi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giorgio.zorzi/32/36593_2.png) [@giorgio.zorzi](https://community.auth0.com/u/giorgio.zorzi)\
**Post date:** [April 14, 2022, 6:45pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/6 "2022-04-14T18:45:40Z")

</div>

Yes, I made sure that both steps are as you described

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 14, 2022, 6:47pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/7 "2022-04-14T18:47:48Z")

</div>

Can you try removing the audience param for the sake of debugging and see if that is causing this error?

---

<div class="post-metadata">

**Author:** ![giorgio.zorzi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giorgio.zorzi/32/36593_2.png) [@giorgio.zorzi](https://community.auth0.com/u/giorgio.zorzi)\
**Post date:** [April 14, 2022, 8:44pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/8 "2022-04-14T20:44:49Z")

</div>

Still getting the same error

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 15, 2022, 1:16pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/9 "2022-04-15T13:16:59Z")

</div>

Great, we can rule that out.

Have you enabled the connection? Also, can you DM me your tenant name and the name of the client?

---

<div class="post-metadata">

**Author:** ![giorgio.zorzi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giorgio.zorzi/32/36593_2.png) [@giorgio.zorzi](https://community.auth0.com/u/giorgio.zorzi)\
**Post date:** [April 18, 2022, 7:02am UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/10 "2022-04-18T07:02:53Z")

</div>

Hi @dan.woda,

Yes, the connection is enabled in the application.

I DM to you the other details

---

<div class="post-metadata">

**Author:** ![giorgio.zorzi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giorgio.zorzi/32/36593_2.png) [@giorgio.zorzi](https://community.auth0.com/u/giorgio.zorzi)\
**Post date:** [April 21, 2022, 12:23pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/11 "2022-04-21T12:23:55Z")

</div>

I figured out the problem.

I was supposed to use

```python
resp = requests.post(
    url=url,
    headers=headers,
    data=data,
)

```

instead of

```python
resp = requests.post(
    url=url,
    headers=headers,
    json=data,
)

```

BTW, I had to change the python library from `http` (the one used in the [tutorial](https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-resource-owner-password-flow)) to `requests` because that was erroring out for me with

```auto
Traceback (most recent call last):
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/gz/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/ __main__.py", line 45, in <module>
    cli.main()
  File "/home/gz/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
    run()
  File "/home/gz/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str(" __main__"))
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/data/repos/cybrik/frontback/src/backend/test.py", line 39, in <module>
    conn.request("POST", url, payload, headers)
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/http/client.py", line 1279, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/http/client.py", line 1325, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/http/client.py", line 1274, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/http/client.py", line 1034, in _send_output
    self.send(msg)
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/http/client.py", line 974, in send
    self.connect()
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/http/client.py", line 1441, in connect
    super().connect()
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/http/client.py", line 945, in connect
    self.sock = self._create_connection(
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/socket.py", line 823, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/home/gz/.pyenv/versions/3.9.7/lib/python3.9/socket.py", line 954, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

```

I suspect that this is a linux-specific error

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 21, 2022, 3:15pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/12 "2022-04-21T15:15:33Z")

</div>

Thanks for posting your solution!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 25, 2022, 9:34pm UTC](https://community.auth0.com/t/call-api-using-resource-owner-password-flow/81751/13 "2022-05-25T21:34:40Z")

</div>


