Predix_Logo
  • Categories
    • Questions
    • Predix | Updates
      • Pricing
      • Product
    • Deloitte - Private
    • How-To
    • Accenture-Private
  • Explore
    • Topics
    • Questions
    • Articles
    • Feedback or Feature Requests
  • Sign in
  • Home /
  • Questions /
avatar image
0
Question by jingliang1.zhang@ge.com · Jan 04, 2017 at 03:09 PM · uaapythontoken

Anyone know how to access UAA token in python?

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.

Comment
Add comment · Show 3
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sabithksme@gmail.com · Jan 04, 2017 at 03:56 PM 0
Share

Possible proxy issue maybe ?

avatar image jingliang1.zhang@ge.com sabithksme@gmail.com · Jan 05, 2017 at 09:47 AM 0
Share

well, but i can access token via Predix toolkit. that doesn't look like proxy issue. Am I right?

avatar image jingliang1.zhang@ge.com sabithksme@gmail.com · Jan 05, 2017 at 01:08 PM 0
Share

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.

4 Replies

  • Sort: 
avatar image
1
Best Answer

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)

Comment
Add comment · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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

Comment
Add comment · Show 3 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Swapna.Vad@ge.com ♦ · Jan 04, 2017 at 04:06 PM 0
Share

Please check the status page as well. ( Currently seems like UAA is reporting an outage) https://status.predix.io

avatar image jingliang1.zhang@ge.com · Jan 05, 2017 at 01:12 PM 0
Share

Thank you. It looks promising though it used library from flask which I probably wont use.

avatar image chethan.rao@exeloncorp.com · Mar 07, 2017 at 12:30 AM 0
Share

This worked fine for me. But, do you have 'logout' function for the same?

avatar image
0

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?

Comment
Add comment · Show 4 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jingliang1.zhang@ge.com · Jan 10, 2017 at 07:26 AM 0
Share

i tried both. but the biggest issue is proxy. After setting proxy right, you are correct a post should be used instead of get.

avatar image Timothy Selaty · Jan 10, 2017 at 10:33 AM 0
Share

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!

avatar image jingliang1.zhang@ge.com Timothy Selaty · Jan 11, 2017 at 07:39 AM 0
Share

Basically it is trial and error... But the voted script works perfectly. Thanks!

avatar image Timothy Selaty · Jan 10, 2017 at 10:36 AM 0
Share

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.

avatar image
0

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!

Comment
Add comment · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

84 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

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

GE Monogram
  • Legal
  • Cookies
  • Forum Terms
  • Contact Us
  • Copyright © 2017 General Electric Company. All rights reserved.


Enterprise
Social Q&A

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Submit your feedback or feature request
  • Categories
  • Questions
  • Predix | Updates
    • Pricing
    • Product
  • Deloitte - Private
  • How-To
  • Accenture-Private
  • Explore
  • Topics
  • Questions
  • Articles
  • Feedback or Feature Requests