Hi all,
I am trying to connect to apidev.scigap.org from the attached
scipt 'test.py'
I am getting the following exception:
apache.airavata.api.error.ttypes.AuthorizationException:
AuthorizationException(message='Error in authenticating or authorizing
user.')
These are the steps I followed for running this script:
1: Created an account on https://testdrive.airavata.org/
2: Got dev admin access on this account
3: Ran the following command with my credentials:
curl --data "username=myusername&password=mypassword"
https://dev.testdrive.airavata.org/api-login
to get the access token
4: Followed the steps in this document
<https://github.com/machristie/airavata-python3-client/blob/master/README.md>
to setup the environment
5: Ran the attached program: test.py
Please suggest.
Best Wishes,
Saurabh Agrawal
LinkedIn <https://www.linkedin.com/in/saurabh-agrawal-1a048b118i> Github
<https://github.com/saurabhagrawal0412>
from apache.airavata.api import Airavata
from apache.airavata.api.ttypes import *
from apache.airavata.model.workspace.ttypes import *
from apache.airavata.model.security.ttypes import AuthzToken
import requests
from thrift import Thrift
from thrift.transport import TSSLSocket
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
import configparser
# For Keycloak the username is in the 'preferred_username' claim of the
userinfo response
username_claim = 'preferred_username'
def get_transport(hostname, port):
# Create a socket to the Airavata Server
# TODO: validate server certificate
transport = TSSLSocket.TSSLSocket(hostname, port, validate=False)
# Use Buffered Protocol to speedup over raw sockets
transport = TTransport.TBufferedTransport(transport)
return transport
def get_airavata_client(transport):
# Airavata currently uses Binary Protocol
protocol = TBinaryProtocol.TBinaryProtocol(transport)
# Create a Airavata client to use the protocol encoder
airavataClient = Airavata.Client(protocol)
return airavataClient
def get_authz_token(token):
return AuthzToken(accessToken=token, claimsMap={'gatewayID': "default",
'userName': "saurabh0412"})
def get_all_projects(airavataClient, authzToken, gatewayId, username):
projectLists = airavataClient.getUserProjects(authzToken, gatewayId,
username, -1, 0)
return projectLists
if __name__ == '__main__':
config = configparser.ConfigParser()
config.read('airavata-client.ini')
username = 'saurabh0412'
gatewayID = 'default'
token = config['credentials']['AccessToken']
authz_token = get_authz_token(token)
print(authz_token)
hostname = 'apidev.scigap.org'
port = '9930'
transport = get_transport(hostname, port)
print('Printing transport -> ' + str(transport))
transport.open()
airavataClient = get_airavata_client(transport)
projects = get_all_projects(airavataClient, authz_token, gatewayID,
username)
print('Printing projects -> ' + str(projects))
api_version = airavataClient.getAPIVersion(authz_token)
print('api_version -> ' + str(api_version))
transport.close()