问题
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