google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

Unable to make an API call "discovery.build", throwing error 400 for dialogflow service

Open charul97 opened this issue 5 years ago • 5 comments

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()
webhook_name= "projects/<project-name>/locations/us-central1/agents/<agent-id>"
service_client = discovery.build('dialogflow', 'v3', credentials=credentials, discoveryServiceUrl="https://www.googleapis.com/discovery/v1/apis/us-central1-dialogflow/v3/rest")

The above code throws the following error : HttpError: <HttpError 400 when requesting https://dialogflow.googleapis.com/v3/projects//locations/us-central1/agents//webhooks/?alt=json returned "Please switch to 'us-central1-dialogflow.googleapis.com' to access resources located in 'us-central1'.". Details: "Please switch to 'us-central1-dialogflow.googleapis.com' to access resources located in 'us-central1'.">

charul97 avatar Aug 23 '21 14:08 charul97

Hi @charul97,

Static discovery artifacts which are used to build clients are now included in version 2.x.x of google-api-python-client. Please can you try the following code to build the client using the static discovery artifacts?

from googleapiclient import discovery
service_client = discovery.build('dialogflow', 'v3')

Moving forward, you'll only need to provide discoveryServiceUrl when you need to access a discovery artifact which is not part of the public directory here.

parthea avatar Aug 23 '21 16:08 parthea

Hi @charul97,

Static discovery artifacts which are used to build clients are now included in version 2.x.x of google-api-python-client. Please can you try the following code to build the client using the static discovery artifacts?

from googleapiclient import discovery
service_client = discovery.build('dialogflow', 'v3')

Moving forward, you'll only need to provide discoveryServiceUrl when you need to access a discovery artifact which is not part of the public directory here.

I get the same error even if I remove discoveryServiceUrl

charul97 avatar Aug 23 '21 18:08 charul97

Hi @charul97, I'm not able to reproduce the problem. Please can you share the version of google-api-python-client that you're using with pip show google-api-python-client?

parthea avatar Aug 23 '21 19:08 parthea

Hi @charul97, I'm not able to reproduce the problem. Please can you share the version of google-api-python-client that you're using with pip show google-api-python-client?

Name: google-api-python-client Version: 2.2.0 Summary: Google API Client Library for Python

charul97 avatar Aug 24 '21 09:08 charul97

Regretfully I'm not able to reproduce this issue. Please re-open this issue if you're still having trouble. I'm happy to troubleshoot further.

parthea avatar Oct 20 '21 10:10 parthea