首先,如果不添加--trusted-host pypi.python.org
,我几乎无法pip安装任何东西。如果我不包括它,我会得到一个错误的读数
无法获取URLhttps://pypi.python.org/simple/beautifulsoup/:确认ssl证书时出现问题:[ssl:certificate\u VERIFY\u FAILED]certificate VERIFY FAILED(\u ssl.c:748)-跳过`BeautifulSoup
只是一个例子,它发生在所有领域。
另外,如果我运行这个reddit bot代码:
from bs4 import BeautifulSoup
from urllib.parse import urlparse
import requests
import praw
import time
import re
import bs4
import ssl
USERAGENT = 'web:PeskyTrollBot:v0.1 (by /u/ThePeskyWabbit)'
auth = True
def authenticate():
print("Authenticating...")
reddit = praw.Reddit('bot1', user_agent=USERAGENT)
print("Authenticated as {}\n" .format(reddit.user.me()))
return reddit
authenticate()
#while auth:
# try:
# authenticate()
# auth = False
# except:
# print('authentication failed. Retrying in 1 minute.\n')
# time.sleep(60)
我得到错误输出:
C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py
Authenticating...
Traceback (most recent call last):
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 441, in wrap_socket
cnx.do_handshake()
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\SSL.py", line 1716, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\SSL.py", line 1456, in _raise_ssl_error
_raise_current_error()
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 595, in urlopen
self._prepare_proxy(conn)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 816, in _prepare_proxy
conn.connect()
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connection.py", line 326, in connect
ssl_context=context)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 448, in wrap_socket
raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.reddit.com', port=443): Max retries exceeded with url: /api/v1/access_token (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\requestor.py", line 47, in request
return self._http.request(*args, timeout=TIMEOUT, **kwargs)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.reddit.com', port=443): Max retries exceeded with url: /api/v1/access_token (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py", line 20, in <module>
authenticate()
File "C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py", line 17, in authenticate
print("Authenticated as {}\n" .format(reddit.user.me()))
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\models\user.py", line 60, in me
user_data = self._reddit.get(API_PATH['me'])
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\reddit.py", line 367, in get
data = self.request('GET', path, params=params)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\reddit.py", line 472, in request
params=params)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 175, in request
params=params, url=url)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 121, in _request_with_retries
retries, saved_exception, url)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 87, in _do_retry
params=params, url=url, retries=retries - 1)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 121, in _request_with_retries
retries, saved_exception, url)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 87, in _do_retry
params=params, url=url, retries=retries - 1)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 109, in _request_with_retries
data, files, json, method, params, retries, url)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 94, in _make_request
params=params)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\rate_limit.py", line 32, in call
kwargs['headers'] = set_header_callback()
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 135, in _set_header_callback
self._authorizer.refresh()
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\auth.py", line 328, in refresh
password=self._password)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\auth.py", line 138, in _request_token
response = self._authenticator._post(url, **data)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\auth.py", line 29, in _post
data=sorted(data.items()))
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\requestor.py", line 49, in request
raise RequestException(exc, args, kwargs)
prawcore.exceptions.RequestException: error with request HTTPSConnectionPool(host='www.reddit.com', port=443): Max retries exceeded with url: /api/v1/access_token (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
Process finished with exit code 1
最后,如果我准确地执行这段代码:http://praw.readthedocs.io/en/latest/tutorials/refresh_token.html
我得到错误输出:
Traceback (most recent call last):
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 441, in wrap_socket
cnx.do_handshake()
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\SSL.py", line 1716, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\SSL.py", line 1456, in _raise_ssl_error
_raise_current_error()
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 595, in urlopen
self._prepare_proxy(conn)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 816, in _prepare_proxy
conn.connect()
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connection.py", line 326, in connect
ssl_context=context)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 448, in wrap_socket
raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.reddit.com', port=443): Max retries exceeded with url: /api/v1/access_token (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\requestor.py", line 47, in request
return self._http.request(*args, timeout=TIMEOUT, **kwargs)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.reddit.com', port=443): Max retries exceeded with url: /api/v1/access_token (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/JoshLaptop/PycharmProjects/practice/RefreshToken.py", line 95, in <module>
sys.exit(main())
File "C:/Users/JoshLaptop/PycharmProjects/practice/RefreshToken.py", line 89, in main
refresh_token = reddit.auth.authorize(params['code'])
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\models\auth.py", line 52, in authorize
authorizer.authorize(code)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\auth.py", line 202, in authorize
redirect_uri=self._authenticator.redirect_uri)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\auth.py", line 138, in _request_token
response = self._authenticator._post(url, **data)
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\auth.py", line 29, in _post
data=sorted(data.items()))
File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\requestor.py", line 49, in request
raise RequestException(exc, args, kwargs)
prawcore.exceptions.RequestException: error with request HTTPSConnectionPool(host='www.reddit.com', port=443): Max retries exceeded with url: /api/v1/access_token (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
Process finished with exit code 1
我已经更新了pyopenssl。我重新安装了python。我重新启动了。我试过在
try/except
块中进行身份验证。我已经更新了证书。它们似乎都与根本原因有关,例如证书丢失,但除了通过更新pyopenssl
,我找不到关于如何获得正确证书的文档。我不认为这个与编程相关的问题是因为我在安装pip时遇到了与cmd有关的问题。请帮忙!! 最佳答案
这个问题是通过将python直接安装到C:\目录而不是在我的用户配置文件中来解决的。
关于python - 我在不同的python应用程序中遇到多个SSL错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45699061/