Details
-
Type: extRequest
-
Status: Closed
-
Priority: Major
-
Resolution: Done
-
Fix Version/s: 2021
-
Component/s: FIWARE-TECH-HELP
-
Labels:None
-
HD-Chapter:Data
-
HD-Enabler:Cosmos
Description
Hi, please find hereafter a snipped python code to use OAuth2 on Cosmos,
but the services always replies 401, even if token is used.
Username and password for getting the token is the ones of a FIWARE LAB
user.
May you help us?
Thanks in advance for your help,
P.
------------------------------------
import requests
def get_oauth_token():
OAUTH_SERVER = "https://130.206.80.46:13000/cosmos-auth/v1/token"
OAUTH_CONTENT = "grant_type=password&username=XXX&password=XXX"
req_headers =
{'Content-Type': 'application/x-www-form-urlencoded'} r = requests.post(OAUTH_SERVER, data=OAUTH_CONTENT,
headers=req_headers, verify=False)
res = r.json()
return res['access_token']
if _name_ == "_main_":
headers = None
t = get_oauth_token()
if not headers:
headers = {}
headers['X-Auth-Token'] = t
print headers
TEST_GET = "http://130.206.80.46:14000/webhdfs/v1/user/XXXXXX.txt"
TEST_GET_PARAMS = "op=getfilestatus&user.name=XXXX"
response = requests.get(TEST_GET, data=TEST_GET_PARAMS,
headers=headers)
print response
--------------
Pasquale Andriani
Direzione Ricerca e Innovazione - Research & Development Lab
pasquale.andriani@eng.it
Engineering Ingegneria Informatica spa
Via Riccardo Morandi, 32 - 00148 Roma
Tel. +39-06.87594138
Mob. +39 3924698746
Fax. +39-06.83074408
www.eng.it
_______________________________________________
Fiware-lab-help mailing list
Fiware-lab-help@lists.fi-ware.org
https://lists.fi-ware.org/listinfo/fiware-lab-help
Hi,
It sounds well what you are doing... Can you confirm a valid token is gotten when accessing https://cosmos.lab.fiware.org:13000/cosmos-auth/token ? I mean, try everything with a curl before any coding. Just to know if it is a problem of the server or the coding. Paste here the results of the curl, please.
Regards,
Francisco