Might be an old thread but here goes:
I can't seem to generate a token, and I have the same syntax used here.
auth_details = {
    "usernname" : "fakeuser",
    "password" : "fakepassword",
    "grant_type" : "password",
}
uri = "https://secretserver.fakedomain.com/oauth2/token"
headers = { 'Accept': "application/json", 
           'Content-Type': "x-www-form-urlencoded",
        }
response = requests.post(uri,data=auth_details,headers=headers)
This result in Response 406. When I try to see the contents of response:
print(response.text)
<div id="header"><h1>Server Error</h1></div>
<div id="content">
 <div class="content-container"><fieldset>
  <h2>406 - Client browser does not accept the MIME type of the requested page.</h2>
  <h3>The page you are looking for cannot be opened by your browser because it has a file name extension that your browser does not accept.</h3>
 </fieldset></div>
</div>
</body>
I've tried changing the accept type to text/html, and I got a Response 200. But as expected , it's in html format and the details of the token is not there.
Hoping someone can help me here.