首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >空气制动错误: urlopen错误[SSL: CERTIFICATE_VERIFY_FAILED]证书验证失败:无法获取本地颁发者证书

空气制动错误: urlopen错误[SSL: CERTIFICATE_VERIFY_FAILED]证书验证失败:无法获取本地颁发者证书
EN

Stack Overflow用户
提问于 2018-08-10 03:50:34
回答 1查看 3.4K关注 0票数 0

我使用pybrake在Django项目中设置了Airbrake,但是12天前它停止工作了,我正在尝试调试这个问题。

我已经创建了一个带有Pipfileairbrake_test.py的小“测试项目”(我已经在其中打乱了项目密钥和ID):

代码语言:javascript
复制
(pybrake_test2-cU2-tsuL) bash-3.2$ ls
Pipfile         Pipfile.lock        airbrake_test.py

这是airbrake_test.py

代码语言:javascript
复制
import os
import logging
import pybrake

os.environ['AIRBRAKE_PROJECT_ID'] = '112113'
os.environ['AIRBRAKE_PROJECT_KEY'] = '6e936fee123asdfasdf71445de0'


notifier = pybrake.Notifier(project_id=os.getenv('AIRBRAKE_PROJECT_ID'),
                            project_key=os.getenv('AIRBRAKE_PROJECT_KEY'),
                            environment='staging')


airbrake_handler = pybrake.LoggingHandler(notifier=notifier,
                                          level=logging.ERROR)

logger = logging.getLogger('test')
logger.addHandler(airbrake_handler)


def run():
    logger.error('something bad happened')


if __name__ == "__main__":
    run()

下面是pipenv使用的Pipfile

代码语言:javascript
复制
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pybrake = "==0.3.3"

[dev-packages]

[requires]
python_version = "3.7"

我已经测试过了,如果我运行这个脚本,我会得到一个关于pybrake无法找到.git目录的错误,但除此之外,没有任何错误:

代码语言:javascript
复制
(pybrake_test2-cU2-tsuL) bash-3.2$ python airbrake_test.py
2018-08-09 12:42:56,850 - pybrake - ERROR - get_git_revision failed: [Errno 2] No such file or directory: '/Users/kurtpeek/Documents/Scratch/pybrake_test2/.git/HEAD'

我还在我的空气制动控制台上看到了这个错误:

我已经将完全相同的脚本复制到我的“实际”项目目录中的子目录scripts (并将其命名为airbrake_test2.py):

代码语言:javascript
复制
(lucy-web-CVxkrCFK) bash-3.2$ find . -name 'airbrake_test2*'
./scripts/airbrake_test2.py

但是,如果我尝试运行它,我得到一个"unable to get local issuer certificate“错误:

代码语言:javascript
复制
(lucy-web-CVxkrCFK) bash-3.2$ python scripts/airbrake_test2.py
2018-08-09 12:47:08,087 - pybrake - ERROR - get_git_revision failed: [Errno 2] No such file or directory: '/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/.git/HEAD'
2018-08-09 12:47:08,434 - pybrake - ERROR - <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)>

我很困惑为什么它在“测试”项目中工作,而不是在“真正”项目中工作。下面是“real”项目的Pipfile

代码语言:javascript
复制
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
# AWS SDK for Python
boto3 = "==1.7.61"
# Use DATABASE_URL env variable to configure Django application
dj-database-url = "==0.5.0"
# Web framework
django = "==2.0.7"
# Django email integration for transactional ESPs
"django-anymail[mailgun]" = "==3.0"
# Log of changes made to a model
django-auditlog = "==0.4.5"
# Compresses linked and inline JavaScript or CSS into a single cached file
django-compressor = "==2.2"
# Save and retrieve current request object anywhere in your code
django-crequest = "==2018.5.11"
# Blocks people from brute forcing login attempts
django-defender = "==0.5.5"
# Wrap standard Django fields with encryption
django-encrypted-model-fields = "==0.5.5"
# Custom extensions for the Django Framework
django-extensions = "==2.1.0"
# A set of high-level abstractions for Django forms
django-formtools = "==2.1"
# Import and export data in multiple formats (Excel, CSV, JSON, and so on)
django-import-export = "==1.0.1"
# Using more than one form in a single view
django-multi-form-view = "==2.0.0"
# OAuth2 for Django
django-oauth-toolkit = "==1.2.0"
# SASS integration
django-sass-processor = "==0.7"
# Collection of custom storage backends for Django
django-storages = "==1.6.6"
# Two-Factor Authentication for Django
django-two-factor-auth = "==1.7.0"
# Tweak the form field rendering in templates
django-widget-tweaks = "==1.4.2"
# Toolkit for building Web APIs
djangorestframework = "==3.8.2"
# Versioning of Django Rest Framwork API representations
djangorestframework-version-transforms = "==0.5.0"
# Fixtures replacement
factory-boy = "==2.11.1"
# Style Guide Enforcement
flake8 = "==3.5.0"
# Allows tests to travel through time by mocking the datetime module
freezegun = "==0.3.10"
# Python WSGI HTTP Server
gunicorn = "==19.9.0"
# SASS support
libsass = "==0.14.5"
# Newrelic adapter
newrelic = "==3.4.0.95"
# Parsing, formatting, and validating international phone numbers
phonenumbers = "==8.9.10"
# Imaging processing library
pillow = "==5.2.0"
# PostgreSQL adapter
psycopg2 = "==2.7.3"
# Python exception notifier for Airbrake
pybrake = "==0.3.3"
# ISO databases for languages, countries and subdivisions
pycountry = "==18.5.26"
# Extensions to the standard datetime module
python-dateutil = "==2.6.0"
# Loads environment variables from .env file
python-dotenv = "==0.8.2"
# Python wrapper for the Intercom API
python-intercom = "==3.1.0"
# HTTP library
requests = "==2.19.1"
# Python library to capitalize strings
titlecase = "==0.12.0"
# Communication with the Twilio API
twilio = "==6.15.1"
# Static file serving
whitenoise = "==3.3.1"

[dev-packages]
# Tab completion, syntax highlighting, better tracebacks for ipython
ipdb = "==0.11"
# Interactive Python shell
ipython = "==6.4.0"

[requires]
python_version = "3.7.0"

正如您所看到的,pybrake的版本与“测试”项目(版本0.3.3)中的版本完全相同;我能想到的唯一区别是,“测试”项目中的python_version3.7,而“真正”项目中的是3.7.0

你知道为什么我会得到这个错误吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-10 04:05:15

在Airbrake的支持下,我设法通过在/Applications/Python 3.7 (在我的Mac上)中运行Install Certificates.command来解决这个问题:

代码语言:javascript
复制
Kurts-MacBook-Pro-2:Python 3.7 kurtpeek$ pwd
/Applications/Python 3.7
Kurts-MacBook-Pro-2:Python 3.7 kurtpeek$ sudo ./"Install Certificates.command"
 -- pip install --upgrade certifi
The directory '/Users/kurtpeek/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/kurtpeek/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: certifi in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2018.4.16)
 -- removing any existing file or link
 -- creating symlink to certifi certificate bundle
 -- setting permissions
 -- update complete

现在,urlopen()引发的错误消失了:

代码语言:javascript
复制
(lucy-web-CVxkrCFK) bash-3.2$ python scripts/airbrake_test2.py
2018-08-09 13:01:09,867 - pybrake - ERROR - get_git_revision failed: [Errno 2] No such file or directory: '/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/.git/HEAD'

我又在我们的空气制动控制台上看到了这个错误。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51774807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档