Вопрос по python – Python запрашивает выбрасывание SSLError

256

Я работаю над простым сценарием, который включает в себя CAS, проверку безопасности jspring, перенаправление и т. Д. Я хотел бы использовать запросы Python от Кеннета Рейтца, потому что это отличная работа! Тем не менее, CAS требует проверки через SSL, поэтому мне нужно сначала пройти этот шаг. Я не знаю, чего хотят запросы Python? Где должен находиться этот сертификат SSL?

Traceback (most recent call last):
  File "./test.py", line 24, in <module>
  response = requests.get(url1, headers=headers)
  File "build/bdist.linux-x86_64/egg/requests/api.py", line 52, in get
  File "build/bdist.linux-x86_64/egg/requests/api.py", line 40, in request
  File "build/bdist.linux-x86_64/egg/requests/sessions.py", line 209, in request 
  File "build/bdist.linux-x86_64/egg/requests/models.py", line 624, in send
  File "build/bdist.linux-x86_64/egg/requests/models.py", line 300, in _build_response
  File "build/bdist.linux-x86_64/egg/requests/models.py", line 611, in send
requests.exceptions.SSLError: [Errno 1] _ssl.c:503: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Error: User Rate Limit Exceeded TankorSmash
Error: User Rate Limit Exceeded pan7an
Error: User Rate Limit Exceeded Piotr Dobrogost

Ваш Ответ

18   ответов
9

verify=False.

import requests

url = "Write your url here"

returnResponse = requests.get(url, verify=False)
10

/etc/ssl/certs/

import requests
verify='/etc/ssl/certs/cacert.org.pem'
response = requests.get('https://lists.cacert.org', verify=verify)

pem

pem/usr/local/lib/python2.7/dist-packages/requests/cacert.pem

Related postError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded/usr/local/lib/python2.7/dist-packages/requests/cacert.pemError: User Rate Limit Exceeded
2

requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS'

Error: User Rate Limit Exceeded
14

requestspyvmomicacert.pemcacert.pem

windows

C:\>python -c "import requests; print requests.certs.where()"
c:\Python27\lib\site-packages\requests-2.8.1-py2.7.egg\requests\cacert.pem

linux

#  (py2.7.5,requests 2.7.0, verify not enforced)
[email protected]:~/# python -c "import requests; print requests.certs.where()"
/usr/lib/python2.7/dist-packages/certifi/cacert.pem

#  (py2.7.10, verify enforced)
[email protected]:~/# python -c "import requests; print requests.certs.where()"
/usr/local/lib/python2.7/dist-packages/requests/cacert.pem

update

REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-bundle.crt python -c "import requests; requests.get('https://somesite.com';)"
97

:

Requests can verify SSL certificates for HTTPS requests, just like a web browser. To check a host’s SSL certificate, you can use the verify argument:

>>> requests.get('https://kennethreitz.com', verify=True)

verify=False

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded TedBurrows
Error: User Rate Limit Exceeded TedBurrows
Error: User Rate Limit Exceeded
44

verify:

cafile = 'cacert.pem' # http://curl.haxx.se/ca/cacert.pem
r = requests.get(url, verify=cafile)

verify=Truerequests

Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededrequestsError: User Rate Limit Exceededpython -mrequests.certsError: User Rate Limit Exceeded
Error: User Rate Limit Exceededcacert.pemError: User Rate Limit Exceededcertifi.io
Error: User Rate Limit Exceededcacert.pem is CA certificates extracted from Mozilla (by cURL)Error: User Rate Limit ExceededcanError: User Rate Limit Exceeded
1

debug purposes only

import requests.api
import warnings


def requestspatch(method, url, **kwargs):
    kwargs['verify'] = False
    return _origcall(method, url, **kwargs)

_origcall = requests.api.request
requests.api.request = requestspatch
warnings.warn('Patched requests: SSL verification disabled!')

Never use in production!

329

quickestverify=False:

requests.get('https://example.com', verify=False)

This will expose your application to security risks, such as man-in-the-middle attacks.

maybut really should not go to production software.

verify.pem

verify

True: causes the certificate to validated against the library's own trusted certificate authorities (Note: you can see which Root Certificates Requests uses via the Certifi library, a trust database of RCs extracted from Requests: Certifi - Trust Database for Humans). False: bypasses certificate validation completely. Path to a CA_BUNDLE file for Requests to use to validate the certificates.

cert

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededverify=FalseError: User Rate Limit Exceeded
Error: User Rate Limit ExceededveryError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
10

import urllib3

urllib3.disable_warnings()

verify=Falserequest.getpost

0

pyenv virtualenv 3.4.6 myvenv
pyenv activate myvenv
pip install -r requirements.txt
32

$ pip install -U requests[security]

Tested on Python 2.7.6 @ Ubuntu 14.04.4 LTS Tested on Python 2.7.5 @ MacOSX 10.9.5 (Mavericks)

Error: User Rate Limit Exceeded2.4.1 (2014-09)Error: User Rate Limit ExceededcertifiError: User Rate Limit Exceeded

Error: User Rate Limit Exceededwithout verify=FalseError: User Rate Limit Exceededrequests.get(url, verify=False)Error: User Rate Limit Exceededrequests[security]Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededpip install -U requests[security] --no-cacheError: User Rate Limit Exceededpip install certifi==2015.04.28
Error: User Rate Limit Exceededpip install --upgrade pipError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededstackoverflow.com/a/12865159/798575
24

REQUESTS_CA_BUNDLE

from boto3.session import Session
import os

# debian
os.environ['REQUESTS_CA_BUNDLE'] = os.path.join(
    '/etc/ssl/certs/',
    'ca-certificates.crt')
# centos
#   'ca-bundle.crt')

~/.bashrc

REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt # ca-bundle.crt
export REQUESTS_CA_BUNDLE
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
1

pip install --upgrade certifi      # hold your breath..

open /Applications/Python\ 3.6/Install\ Certificates.command  # please replace 3.6 here with your suitable python version
0

import certifi # This should be already installed as a dependency of 'requests'
requests.get("https://example.com", verify=certifi.old_where())
0

cat StartComClass1.pem >> .virtualenvs/caldav/lib/python2.7/site-packages/pip/_vendor/requests/cacert.pem
cat temp/StartComClass1.pem >> .virtualenvs/caldav/lib/python2.7/site-packages/requests/cacert.pem

7

requests[security]==2.7.0  # not 2.18.1
cryptography==1.9  # not 2.0

OpenSSL 1.0.2g 1 Mar 2016

verify=False

13

sudo pip uninstall -y certifi
sudo pip install certifi==2015.04.28
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
5

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

sudo apt-get install ca-certificates

Error: User Rate Limit Exceeded

sudo apt-get install ntpdate
sudo ntpdate -u ntp.ubuntu.com

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededcertifi.io

Похожие вопросы