使用谷歌API客户端库时SSLError

时间:2013-08-26 22:50:42

标签: python google-api-python-client

我在Ubuntu服务器上使用google api客户端库。虽然脚本在我自己的机器上工作正常,但在服务器上它失败了SSLError:

File "/home/default/bigbluebutton/youtube/uploader/uploadvideo.py", line 78, in authorize
    credentials = flow.step2_exchange(code)        
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py", line 1283, in step2_exchange
    headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1252, in _conn_request
    conn.connect()
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1021, in connect
    self.disable_ssl_certificate_validation, self.ca_certs)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 80, in _ssl_wrap_socket
    cert_reqs=cert_reqs, ca_certs=ca_certs)
  File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket
    ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 141, in __init__
    ciphers)
ssl.SSLError: [Errno 185090050] _ssl.c:340: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

如何解决这个问题? SSL有问题吗?

2 个答案:

答案 0 :(得分:1)

适用于我的解决方案是将cacerts.txt的权限更改为您自己的用户(而不是root用户)。或以root身份运行。你可以在/usr/local/lib/python2.7/dist-packages/httplib2/cacerts.txt找到这些文件

答案 1 :(得分:0)

我有同样的问题,我猜的原因是因为无法加载相应的证书。 以下是httplib2 / init .py的代码段,它会加载证书。

    try:
        # Users can optionally provide a module that tells us where the CA_CERTS
        # are located.
        import ca_certs_locater
        CA_CERTS = ca_certs_locater.get()
    except ImportError:
        # Default CA certificates file bundled with httplib2.
        CA_CERTS = os.path.join(
            os.path.dirname(os.path.abspath(__file__ )), "cacerts.txt")

httplib2 / init .py位置:/usr/local/lib/python2.7/dist-packages/httplib2-0.8-py2.7.egg/httplib2/ init 的.py

在上面的代码中,ca_certs_locater从基本OS加载证书颁发机构文件,而不是httplib2包中的证书颁发机构文件。 如果ca_certs_locater模块不存在,则从文件cacerts.txt加载证书。

在我的情况下,模块不存在,所以它从文件“cacerts.txt”加载,我不确定是否存在。我通过安装模块ca_certs_locater解决了这个问题。 / p>