I want to obtain authentication token using urllib2 in python.
My program is (I changed credentials):
import urllib2
import urllib
USER_NAME = 'me'
USER_PASSWORD = 'mypass'
url = "http://myurl.org/oauth/token"
query_args = { "grant_type":"password",
"username":USER_NAME,
"password":USER_PASSWORD,
"client_secret":'123',
'client_id':'456'}
encoded_args = urllib.urlencode(query_args)
print urllib2.urlopen(url, data=encoded_args).read()
The result of running is 403 Error: Forbidden.
However I can obtain the authentication token using curl in terminal:
curl -X POST "url" -d "credentials"
I used "url" and "credentials" from the python code (to obtain "credentials" string I prinded out encoded_args).
How to get authentication token using urllib2?