
Jaime Fernando Ordóñez peña
Preguntaprofe o compañeros ayuda tengo problemas en conectar la api de dialogflow cx, ud me podría ayudar como comunicarme el problema es de autenticacion o si tienen un metodo que lo puedan compartir por fis
from google.auth.transport import requests as google_requests
from google.oauth2 import service_account
import httpx
SCOPES = [“https://www.googleapis.com/auth/dialogflow”]
CRED = "keys.json"
credentials = service_account.Credentials.from_service_account_file(
CRED, scopes=SCOPES)
credentials.refresh(google_requests.Request())
token = credentials.token
headers = {
“Content-Type”: “application/json; charset=utf-8”,
“Authorization”: “Bearer” + token
},
payload = {
"queryInput": { "text": { "text": "Hola fordez" }, "languageCode": "en" }, "queryParams": { "timeZone": "America/Los_Angeles" }
},
PROJECT_ID = "chatrobot-1dd75"
AGENT_ID = "dd7f0320-bd7f-40f8-95e0-5b040a800ab7"
REGION_ID = "us-central1"
SESSION_ID = "test-session-123"
url = ‘https://{0}-dialogflow.googleapis.com/v3/projects/{1}/locations/{2}/agents/{3}/sessions/{4}:detectIntent’.format(
REGION_ID, PROJECT_ID, REGION_ID, AGENT_ID, SESSION_ID)
response = httpx.post(url, headers=headers, json=payload)
result = response.json
response.raise_for_status()
print(result)
Traceback (most recent call last):
File “/home/fordez/bot-facebook-restaurant/bot/dialogflowCX.py”, line 42, in <module>
response.raise_for_status()
File “/home/fordez/anaconda3/envs/bot-restaurant/lib/python3.10/site-packages/httpx/_models.py”, line 1508, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error ‘401 Unauthorized’ for url 'https://us-central1-dialogflow.googleapis.com/v3/projects/chatrobot-1dd75/locations/us-central1/agents/dd7f0320-bd7f-40f8-95e0-5b040a800ab7/sessions/test-session-123:detectIntent’
For more information check: https://httpstatuses.com/401