2016-08-10 6 views
5

मैं google क्लाउड वाक् API साथ अजगर का उपयोग कर रहा उपयोग करने का प्रयास मैंने किया ubuntu पर और खिड़कियों पर साथ ही "How to use google speech recognition api in python?" में सभी चरणों और जब मैं से सरल स्क्रिप्ट चलाने के लिए कोशिश कर रहा है - यहाँ "https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/api/speech_rest.py"गूगल बादल भाषण एपीआई 403 फेंक जब यह

मैं अगले त्रुटि मिलती है: <HttpError 403 when requesting https://speech.googleapis.com/$discovery/rest?version=v1beta1 returned "Google Cloud Speech API has not been used in project google.com:cloudsdktool before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=google.com:cloudsdktool then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.">

क्या अजीब है कि मैं "cloudsdktool"

मैं चलाने "gcloud init" नाम से परियोजना की जरूरत नहीं है, और है जब मैंने "gcloud auth a" के साथ सेवा खाता कुंजी बनाई, तो जेएसओ फ़ाइल को मिला ctivate-सेवा-खाता --key-फ़ाइल = jsonfile "कमांड, मैं गूगल साख बनाने के लिए वातावरण चर लिनक्स में करने की कोशिश की है और अभी भी मैं एक ही मालिश प्राप्त

+0

संबंधित चर्चा https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues/706:

यहाँ grpc के लिए बदली हुई स्क्रिप्ट कर रहे हैं। ऐसा लगता है कि आपको जेसन फ़ाइल के साथ एक ऑथ चाहिए। –

+1

[Google विजन एपीआई टेक्स्ट डिटेक्शन का संभावित डुप्लिकेट पायथन उदाहरण प्रोजेक्ट का उपयोग करता है: "google.com:cloudsdktool" और मेरी खुद की परियोजना नहीं] (http://stackoverflow.com/questions/38048320/google-vision-api-text-detection -पीथॉन-उदाहरण-उपयोग-प्रोजेक्ट-google-comclouds) –

उत्तर

3

तो मुझे लगता है कि इस समस्या को ठीक करने के दो तरीके पाया:

1 - यदि Google क्लाउड एसडीके और क्लाउड भाषण का उपयोग बीटा संस्करण में है तो आपको 'gcloud init' के बजाय 'gcloud beta init' चलाने की आवश्यकता है और फिर जेसन फ़ाइल

2 - यदि आप नहीं चाहते हैं Google से क्लाउड एसडीके का उपयोग करें, आप जेसन फ़ाइल को सीधे पाइथन ऐप

में विधियों के लिए यहां कर सकते हैं आर इस:

from oauth2client.client import GoogleCredentials 

GoogleCredentials.from_stream('path/to/your/json') 

तो तुम सिर्फ creds पर गुंजाइश और को अधिकृत बना सकते हैं या grpc का उपयोग कर यदि (स्ट्रीमिंग) तुम सिर्फ उदाहरण की तरह हेडर के गुजरती हैं।

def make_channel(host, port): 
    """Creates an SSL channel with auth credentials from the environment.""" 
    # In order to make an https call, use an ssl channel with defaults 
    ssl_channel = implementations.ssl_channel_credentials(None, None, None) 

    # Grab application default credentials from the environment 
    creds = GoogleCredentials.from_stream('path/to/your/json').create_scoped([SPEECH_SCOPE]) 
    # Add a plugin to inject the creds into the header 
    auth_header = (
     'Authorization', 
     'Bearer ' + creds.get_access_token().access_token) 
    auth_plugin = implementations.metadata_call_credentials(
     lambda _, cb: cb([auth_header], None), 
     name='google_creds') 

    # compose the two together for both ssl and google auth 
    composite_channel = implementations.composite_channel_credentials(
     ssl_channel, auth_plugin) 

    return implementations.secure_channel(host, port, composite_channel) 
+0

धन्यवाद, यह बीटा में अन्य पुस्तकालयों के लिए भी हल करता है, मेरे मामले में भाषा एपीआई: http://stackoverflow.com/questions/38048320/google-vision- api-पाठ-खोज-अजगर-उदाहरण-उपयोग करता है-परियोजना-google-comclouds – Neurus

संबंधित मुद्दे