在我的生产服务器中,突然pyhton-requests库在与第三方应用程序进行https连接时抛出此错误。
提出意外:SSLError(SSLError("糟糕的ca_certs:' /home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/requests/cacert.pem& #39;",错误([('系统库',' fopen','没有这样的文件或目录'),' BIO例程',' BIO_new_file','没有这样的文件'),(' x509证书例程',' X509_load_cert_crl_file',&# 39; system lib')],)),),)
请提出此异常背后的一些解决方案和原因。
编辑:
Traceback (most recent call last):
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/opt/vogo/api/api/api/celery.py", line 146, in spreadsheets_management
ss = gs.open_by_key("10K_0JGCVZjngWo7dr1CTeRJ1rAhMWxAGxHbl_NworeU")
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/gspread/client.py", line 105, in open_by_key
feed = self.get_spreadsheets_feed()
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/gspread/client.py", line 155, in get_spreadsheets_feed
r = self.session.get(url)
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/gspread/httpsession.py", line 73, in get
return self.request('GET', url, params=params, **kwargs)
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/gspread/httpsession.py", line 65, in request
response = func(url, data=data, params=params, headers=request_headers, files=files, json=json)
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/requests/sessions.py", line 480, in get
"""
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
:param allow_redirects: (optional) Set to True by default.
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
File "/home/ubuntu/.virtualenvs/api/local/lib/python2.7/site-packages/requests/adapters.py", line 447, in send
python版本:2.7.6
python-requests版本:2.18.4
编辑:我的代码
def request(self, method, url, data=None, params=None, headers=None, files=None, json=None):
if data and isinstance(data, bytes):
data = data.decode()
if data and not isinstance(data, basestring):
data = urlencode(data)
if data is not None:
data = data.encode('utf8')
# If we have data and Content-Type is not set, set it...
if data and not headers.get('Content-Type', None):
headers['Content-Type'] = 'application/x-www-form-urlencoded'
request_headers = self.headers.copy()
if headers:
for k, v in headers.items():
if v is None:
del request_headers[k]
else:
request_headers[k] = v
try:
# self.requests_session = requests.Session() // this is init. before
func = getattr(self.requests_session, method.lower())
except AttributeError:
raise RequestError("HTTP method '{}' is not supported".format(method))
response = func(url, data=data, params=params, headers=request_headers, files=files, json=json)
if response.status_code > 399:
raise RequestError(response.status_code, "{0}: {1}".format(
response.status_code, response.content))
return response