У меня возникла проблема, когда я пытаюсь преобразовать Postman OAuth 2.0 в Python3. Я пытался исследовать, но мне кажется, к сожалению, я не нашел ни одного примера Вот мой код:
from rauth import OAuth2Service
import json
def get_token(client_id, client_secret):
access_token = None
service = OAuth2Service(
name = "Viafoura",
client_id=client_id,
client_secret=client_secret,
access_token_url='https://auth.viafoura.io/authorize_client'
)
data = {
'scope': 'xxxxx-xxxx-xxxx-xxxx-xxxxx',
'grant_type': 'client_credentials'
}
session = service.get_auth_session(data=data)
access_token = session
Вот OAuth 2.0 на Postman, и он работает:
Я хочу получить access_token через Python3. Может ли кто-нибудь помочь мне в этом?





Может вам поможет, пример с базовым алгоритмом 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 = None
try:
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)
Вам нужно исправить точку доступа, тип гранта. Этот исходный код можно найти здесь
Извините, я не могу напрямую помочь с библиотекой Viafoura и OAuth2Service.