It works fine using predix toolkit. But I want to write python program to access token (then ingest data to time series). I looked curl which is: curl 'https://7b70b04a-4402-4bdc-8fda-1ca7c6d94d25.predix-uaa.run.aws-usw02-pr.ice.predix.io/oauth/token' -H 'Pragma: no-cache' -H 'content-type: application/x-www-form-urlencoded' -H 'Cache-Control: no-cache' -H 'authorization: Basic XXX' --data 'client_id=XX&grant_type=client_credentials'
So I converted it python: import requests headers = { 'Pragma': 'no-cache', 'content-type': 'application/x-www-form-urlencoded', 'Cache-Control': 'no-cache', 'authorization': 'Basic XXX'} data = { 'client_id': 'XX', 'grant_type': 'client_credentials'}
uaa_issuerID = r'https://7b70b04a-4402-4bdc-8fda-1ca7c6d94d25.predix-uaa.run.aws-usw02-pr.ice.predix.io/oauth/token'
r = requests.get(uaa_issuerID, headers=headers, data=data)
But I get connection error below: HTTPSConnectionPool(host='7b70b04a-4402-4bdc-8fda-1ca7c6d94d25.predix-uaa.run.aws-usw02-pr.ice.predix.io', port=443): Max retries exceeded with url: /oauth/token (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 11004] getaddrinfo failed',))
Any idea how to make it work? I know I can use access token first on Predix toolkit and then start data ingestion. But it is preferred to automate the whole process.
well, but i can access token via Predix toolkit. that doesn't look like proxy issue. Am I right?
just tested a few more cases, turns out proxy does need to be set. Before setting proxy in environment variable, I couldn't connect to internet at all in python... After setting proxy, i am able to connect internet using python library.
Answer by jingliang1.zhang@ge.com · Jan 10, 2017 at 07:28 AM
For those of you interested in this topic, the working script is: import requests import base64 encoded = base64.b64encode(username + ":" + password) headers = {'authorization': 'Basic ' + encoded} data = { 'client_id': username, 'grant_type': 'client_credentials'}
r = requests.post(uaa_issuerID, headers=headers, data=data)
Answer by Swapna.Vad@ge.com · Jan 04, 2017 at 04:04 PM
Following is the sample of the python application with UAA integration. https://github.com/swapnavad/python-uaa-microservice-template
Please check the status page as well. ( Currently seems like UAA is reporting an outage) https://status.predix.io
Thank you. It looks promising though it used library from flask which I probably wont use.
This worked fine for me. But, do you have 'logout' function for the same?
Answer by Timothy Selaty · Jan 09, 2017 at 12:15 PM
Are you sure your problem isn't that you making a GET
request to an otherwise POST
endpoint?
i tried both. but the biggest issue is proxy. After setting proxy right, you are correct a post should be used instead of get.
I figured that was your problem. Looks like your code hasn't changed, minus you removed the content-type
and cache-control
headers. Be sure to vote the correct answer. Thanks!
Basically it is trial and error... But the voted script works perfectly. Thanks!
Also note that the r
in front of the string in the uaa_issuerID isn't necessary since you don't have backslashes for it to use as a literal string.
Answer by jingliang1.zhang@ge.com · Jan 06, 2017 at 02:00 PM
Turn out it is proxy issue. HAVE TO set proxy before launching python..... now it works!
Passing token around an app 1 Answer
How do I know how many tokens have been issued. 2 Answers
UAA with Python in Django? 2 Answers
What is the maximum limit for Access token validity in Shared UAA 0 Answers
UAA logout function in Python 1 Answer