Skip to content Skip to sidebar Skip to footer

How To Convert Postman Oauth 2.0 To Python

I have been getting the issue when I'm trying to convert Postman OAuth 2.0 to Python3. I tried to research but seems unfortunate for me, I did not find any example Here is my code

Solution 1:

Maybe it can help you, an example with the basic algorithm of OAuth2

#!/usr/bin/env python3# -*- coding: utf-8 -*-from requests import post, auth, exceptions
from json import loads

if __name__ == '__main__':

    client_id = ''
    client_secret = ''
    user = ''
    password = ''

    access_point = 'https://account.lab.fiware.org/oauth2/token'
    grant_type = 'password'

    headers = {'Content-Type': 'application/x-www-form-urlencoded'}

    auth = auth.HTTPBasicAuth(client_id, client_secret)

    data = {'grant_type': grant_type,
            'username': user,
            'password': password}

    resp = Nonetry:
        resp = post(access_point, auth=auth, data=data, headers=headers, timeout=5)
    except exceptions.ConnectionError:
        exit(1)

    if resp.status_code == 200:
        resp = loads(resp.text)
        if'access_token'in resp:
            print(resp['access_token'])
            exit(0)

    exit(1)

You need to fix access point, grant type. This source code can be found here

Sorry, I can't help directly with Viafoura and OAuth2Service library.

Post a Comment for "How To Convert Postman Oauth 2.0 To Python"