【问题标题】:Google Cloud Speech API - certificate verify failed in PythonGoogle Cloud Speech API - Python 中的证书验证失败
【发布时间】:2018-05-15 12:46:49
【问题描述】:

我正在使用SpeechRecognition 库。

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')

上面的代码运行时出现错误——

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证 失败 (_ssl.c:777)

音频文件和 api-key 文件已就位。

【问题讨论】:

    标签: python-3.x google-speech-api google-cloud-speech


    【解决方案1】:

    我通过直接在python中编辑谷歌语音客户端库的代码,设法通过代理进行消费。具体来说,我在以下位置编辑了文件(在您的情况下可能会有所不同):

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

    类Request,方法call,有这样一行:

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

    我在该调用中添加了参数 verify=False,它将忽略 SSL 证书验证。但是,不建议这样做,因为会导致安全问题。如果您碰巧在代理中拥有 CA 的证书,则将 verify=False 替换为 cert="/local/address/to/ca/cert"。这是我的工作方式:

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

    【讨论】:

      猜你喜欢
      • 2016-05-19
      • 2018-06-14
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-02
      • 2015-09-05
      • 2020-12-15
      相关资源
      最近更新 更多