OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to get access Token from Amadesu API on Python

  • Thread starter Thread starter tensai_bootleg
  • Start date Start date
T

tensai_bootleg

Guest
I can't get access token from Amadeus Flight API authentication process using requests and oauth_lib. https://developers.amadeus.com/self...eys/authorization/#requesting-an-access-token

Using Requests

Code:
import requests

API_KEY = "twAtndd5V..."
API_SECRET = "xtj..."
AUTH_ENDPOINT = "https://test.api.amadeus.com/v1/security/oauth2/token/"
head = {"Content-Type" : "application/x-www-form-urlencoded"}
response = requests.post(
            url=AUTH_ENDPOINT,
            json={"grant_type" : "client_credentials",
                "client id" : API_KEY,
                "client_secret" : API_SECRET},
            headers=head
)
print(response.text)

Code:
        {
            "error":"invalid_request",      
            "error_description": "No access_token parameter needed for this method",    
            "code": 38187,
            "title": "Invalid parameters"   
        }

Try with oauth2 https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#backend-application-flow

Code:
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient

client = BackendApplicationClient(client_id=API_KEY)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=AUTH_ENDPOINT, client_id=API_KEY, client_secret=API_SECRET)

Code:
    token = oauth.fetch_token(token_url=AUTH_ENDPOINT, client_id=API_KEY, client_secret=API_SECRET)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests_oauthlib\oauth2_session.py", line 406, in fetch_token
    self._client.parse_request_body_response(r.text, scope=self.scope)
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py", line 427, 
in parse_request_body_response
    self.token = parse_token_response(body, 
scope=scope)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 441, in parse_token_response
    validate_token_parameters(params)       
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 448, in validate_token_parameters
    raise_from_error(params.get('error'), params)
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\oauthlib\oauth2\rfc6749\errors.py", line 399, in raise_from_error
    raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request) No access_token parameter needed for this method
<p>I can't get access token from Amadeus Flight API authentication process using requests and oauth_lib.
<a href="https://developers.amadeus.com/self...eys/authorization/#requesting-an-access-token" rel="nofollow noreferrer">https://developers.amadeus.com/self...eys/authorization/#requesting-an-access-token</a></p>
<p>Using Requests</p>
<pre><code>import requests

API_KEY = "twAtndd5V..."
API_SECRET = "xtj..."
AUTH_ENDPOINT = "https://test.api.amadeus.com/v1/security/oauth2/token/"
head = {"Content-Type" : "application/x-www-form-urlencoded"}
response = requests.post(
url=AUTH_ENDPOINT,
json={"grant_type" : "client_credentials",
"client id" : API_KEY,
"client_secret" : API_SECRET},
headers=head
)
print(response.text)
</code></pre>
<pre><code> {
"error":"invalid_request",
"error_description": "No access_token parameter needed for this method",
"code": 38187,
"title": "Invalid parameters"
}
</code></pre>
<p>Try with oauth2 <a href="https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#backend-application-flow" rel="nofollow noreferrer">https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#backend-application-flow</a></p>
<pre><code>from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient

client = BackendApplicationClient(client_id=API_KEY)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=AUTH_ENDPOINT, client_id=API_KEY, client_secret=API_SECRET)
</code></pre>
<pre><code> token = oauth.fetch_token(token_url=AUTH_ENDPOINT, client_id=API_KEY, client_secret=API_SECRET)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests_oauthlib\oauth2_session.py", line 406, in fetch_token
self._client.parse_request_body_response(r.text, scope=self.scope)
File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py", line 427,
in parse_request_body_response
self.token = parse_token_response(body,
scope=scope)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 441, in parse_token_response
validate_token_parameters(params)
File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 448, in validate_token_parameters
raise_from_error(params.get('error'), params)
File "C:\Users\asdf\AppData\Local\Programs\Python\Python312\Lib\site-packages\oauthlib\oauth2\rfc6749\errors.py", line 399, in raise_from_error
raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request) No access_token parameter needed for this method
</code></pre>
 

Latest posts

A
Replies
0
Views
1
Ashrik Ahamed
A
A
Replies
0
Views
1
Ashrik Ahamed
A

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top