Google Cloud Speech API - certificate verify failed in Python

冷暖自知 提交于 2019-12-13 06:20:35

问题


I'm using SpeechRecognition library.

import speech_recognition as sr

AUDIO_FILE = 'test_audio.wav'

with open("api-key.json") as f:
    GOOGLE_CLOUD_SPEECH_CREDENTIALS = f.read()

r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
        audio = r.record(source)

print('Starting recognition...')
print(r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS))
print('Completed')

When above code is run, an error occurs -

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

The audio file and api-key files are in place.


回答1:


I managed to consume through proxy by directly editing the code of google speech client library in python. Specifically I edited the file at(it might be different in your case):

lib/python3.6/site-packages/google/auth/transport/requests.py

the class Request, method call, there is a line like:

response = self.session.request(method, url, data=body, headers=headers, timeout=timeout)

I added the parameter verify=False to that call which will just ignore SSL certificate verifications. However that is not recommended since incurs in security issues. If you happen to have the certificates of the CA in the proxy you replace verify=False with cert="/local/address/to/ca/cert". Here is how I have it working:

 response = self.session.request(method, url, data=body, headers=headers, timeout=timeout,verify=False,**kwargs)


来源:https://stackoverflow.com/questions/50350613/google-cloud-speech-api-certificate-verify-failed-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!