Я получаю ошибку 401 при создании веб-токена JWT json и публикации - PullRequest
0 голосов
/ 15 мая 2018

Я генерирую JWT json веб-токен с ключом учетной записи службы Google и пытаюсь опубликовать данные, но получаю ошибку 401 , здесь я использую клиентскую библиотеку Google

    def generate_jwt():
    with open("service_account_file.json") as json_file:
        service_account_file_opened= json.load(json_file)

    signer = google.auth.crypt.RSASigner.from_service_account_file("service_account_file.json")
    now = int(time.time())
    expires = now + 3600  # One hour in seconds

    payload = {
        'iat': now,
        'exp': expires,
        '**aud**': 'https://www.googleapis.com/auth/actions.fulfillment.conversation',
        '**iss**': 'notifications@eprint-9ff89.iam.gserviceaccount.com',
        '**sub**': 'notifications@eprint-9ff89.iam.gserviceaccount.com',
        'email': 'notifications@eprint-9ff89.iam.gserviceaccount.com'
    }

    jwt = google.auth.jwt.encode(signer, payload)

    return jwt

hed = {'Authorization': 'Bearer {}'. Format (generate_jwt ())}

url = 'https://actions.googleapis.com/v2/conversations:send'
response = requests.post(url, data=json.dumps(notif), headers=hed)
    print(response)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...