Hi, all.
I am trying to get auth token using password mechanism using python 3. Earlier I did it with python 2 and it is still working fine. I used urllib.urlencode() method to URL encode the request parameters,as required in the API doc. Equivalent of that method in python 3 is urllib.parse.urlencode() but i'm getting below error when executing in python 3.
{"error": "invalid_request", "errors": [{"errorCode": "OAU-156", "message": "Basic authentication header is missing or malformed"}], "error_description": "Basic authentication header is missing or malformed"}
I even printed the resulting string from urlencode method in both cases and it is same. Can't understand what's the problem here? Any insights?
python 3 code:
import urllib.parse
import json
import requests
basic="%s:%s" % ("<my cllient id>","<my cllient secret>")
auth_header = {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
"Authorization": "Basic "+ str(base64.b64encode(basic.encode()))
}
body = urllib.parse.urlencode({
'grant_type': 'password',
'username': "<my number>",
'password': "<my password>"
})
auth_request=requests.request("POST","https://platform.devtest.ringcentral.com/restapi/oauth/token",headers=auth_header,data=body)
print(json.dumps(auth_request.json()))
python 2 code(working):
import urllib
import json
import requests
basic="%s:%s" % ("<my cllient id>","<my cllient secret>")
auth_header = {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
"Authorization": "Basic "+ str(base64.b64encode(basic.encode()))
}
body = urllib.urlencode({
'grant_type': 'password',
'username': "<my number>",
'password': "<my password>"
})
auth_request=requests.request("POST","https://platform.devtest.ringcentral.com/restapi/oauth/token",headers=auth_header,data=body)
print(json.dumps(auth_request.json()))