0

I am trying to access this specific website www.srtr.org . My goal is to obtain the address of all the transplant centers. I am currently having some problems accessing the website. My codes are:

import requests 
from bs4 import BeautifulSoup
url = "https://www.srtr.org"
page = requests.get(url)

I am having some troubles accessing the website. This is the error message that I am reading, can anyone explain or direct me to the correct source to understand where my problem lies and how to solve it?

Error Traceback (most recent call last) /Users/nghl/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/contrib/pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname) 437 try: --> 438 cnx.do_handshake() 439 except OpenSSL.SSL.WantReadError:

/Users/nghl/anaconda/lib/python3.6/site-packages/OpenSSL/SSL.py in do_handshake(self) 1637 result = _lib.SSL_do_handshake(self._ssl) -> 1638 self._raise_ssl_error(self._ssl, result) 1639

/Users/nghl/anaconda/lib/python3.6/site-packages/OpenSSL/SSL.py in _raise_ssl_error(self, ssl, result) 1377 else: -> 1378 _raise_current_error() 1379

/Users/nghl/anaconda/lib/python3.6/site-packages/OpenSSL/_util.py in exception_from_error_queue(exception_type) 53 ---> 54 raise exception_type(errors) 55

Error: [('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

SSLError Traceback (most recent call last) /Users/nghl/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 599 body=body, headers=headers, --> 600 chunked=chunked) 601

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw) 344 try: --> 345 self._validate_conn(conn) 346 except (SocketTimeout, BaseSSLError) as e:

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py in _validate_conn(self, conn) 843 if not getattr(conn, 'sock', None): # AppEngine might not have .sock --> 844 conn.connect() 845

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connection.py in connect(self) 325 server_hostname=hostname, --> 326 ssl_context=context) 327

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/util/ssl_.py in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir) 324 if HAS_SNI: # Platform-specific: OpenSSL with enabled SNI --> 325 return context.wrap_socket(sock, server_hostname=server_hostname) 326

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/contrib/pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname) 444 except OpenSSL.SSL.Error as e: --> 445 raise ssl.SSLError('bad handshake: %r' % e) 446 break

SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

During handling of the above exception, another exception occurred:

SSLError Traceback (most recent call last) /Users/nghl/anaconda/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 437 retries=self.max_retries, --> 438 timeout=timeout 439 )

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 629 clean_exit = False --> 630 raise SSLError(e) 631

SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

During handling of the above exception, another exception occurred:

SSLError Traceback (most recent call last) in () 3 4 url = "https://www.srtr.org" ----> 5 page = requests.get(url)

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/api.py in get(url, params, **kwargs) 70 71 kwargs.setdefault('allow_redirects', True) ---> 72 return request('get', url, params=params, **kwargs) 73 74

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/api.py in request(method, url, **kwargs) 56 # cases, and look like a memory leak in others. 57 with sessions.Session() as session: ---> 58 return session.request(method=method, url=url, **kwargs) 59 60

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 516 } 517 send_kwargs.update(settings) --> 518 resp = self.send(prep, **send_kwargs) 519 520 return resp

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/sessions.py in send(self, request, **kwargs) 637 638 # Send the request --> 639 r = adapter.send(request, **kwargs) 640 641 # Total elapsed time of the request (approximately)

/Users/nghl/anaconda/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 510 except (_SSLError, _HTTPError) as e: 511 if isinstance(e, _SSLError): --> 512 raise SSLError(e, request=request) 513 elif isinstance(e, ReadTimeoutError): 514 raise ReadTimeout(e, request=request)

SSLError: ("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

Humayun Ahmad Rajib
  • 1,502
  • 1
  • 10
  • 22
Han Ng
  • 11
  • 1
  • This is due to the ssl certificate verification failed. Most likely the cert expired or the website using non-trusted CA cert. You can bypass it using `page = requests.get(url, verify=False)`, but this is not recommended due to the security risks that could impose. – thuyein Jul 23 '20 at 02:26
  • Thanks. Can I get know what kind of security risk are you referring to? – Han Ng Jul 23 '20 at 02:35
  • @HanNg https://stackoverflow.com/questions/13076511/security-risks-in-disabling-ssl-certification-for-java-program – ivan_pozdeev Jul 23 '20 at 02:38

0 Answers0