I am currently working on a final exam for a python programming course and can't seem to get past the error below (SSLCertVerificationError) during the unit test. I am attempting to use pull text from a url by a tag and id. I've tried many solutions like running the "install certificates.command" and some answers said it could be a server issue. My instructor said that we cannot use them as a resource so I wanted to exhaust all options before reaching out to them.
Code -
def __init__(self, src, _src_type = 'discover', _content = 'none', _orig_content = 'none'):
self.src = src
self._srctype = _src_type
self._content = None
self._orig_content = None
if re.search('^http', src):
self._src_type = 'url'
elif re.search('txt$', src):
self._src_type = 'path'
else:
self._src_type = 'text'
def set_content_to_tag(self, tag, tag_id=None):
self.tag = tag
self.tag_id = tag_id
if self._src_type == 'url':
r = requests.get(self.src)
self._orig_content = r.text
else:
raise Exception('You are attempting to search an instance that is not a url')
soup = BeautifulSoup(self._orig_content, 'html.parser')
self._content = soup.findall(self.tag, self.tag_id).get_text()
Unittest -
import unittest
url = 'https://www.webucator.com/how-to/address-by-bill-clinton-1997.cfm'
path = 'pride-and-prejudice.txt'
text = '''The outlook wasn't brilliant for the Mudville Nine that day;
the score stood four to two, with but one inning more to play.
And then when Cooney died at first, and Barrows did the same,
a sickly silence fell upon the patrons of the game.'''
class TestTextAnalyzer(unittest.TestCase):
def test_discover_url(self):
ta = TextAnalyzer(url)
self.assertEqual(ta._src_type, 'url')
def test_discover_path(self):
ta = TextAnalyzer(path)
self.assertEqual(ta._src_type, 'path')
def test_discover_text(self):
ta = TextAnalyzer(text)
self.assertEqual(ta._src_type, 'text')
def test_set_content_to_tag(self):
ta = TextAnalyzer(url)
ta.set_content_to_tag('div','content-main')
self.assertEqual(ta._content[0:23], 'Address by Bill Clinton')
Error Message -
Traceback (most recent call last):
File "/Users/user/Library/Python/3.9/lib/python/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/Users/user/Library/Python/3.9/lib/python/site-packages/urllib3/connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "/Users/user/Library/Python/3.9/lib/python/site-packages/urllib3/connectionpool.py", line 1040, in _validate_conn
conn.connect()
File "/Users/user/Library/Python/3.9/lib/python/site-packages/urllib3/connection.py", line 416, in connect
self.sock = ssl_wrap_socket(
File "/Users/user/Library/Python/3.9/lib/python/site-packages/urllib3/util/ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "/Users/user/Library/Python/3.9/lib/python/site-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/Library/Python/3.9/lib/python/site-packages/requests/adapters.py", line 440, in send
resp = conn.urlopen(
File "/Users/user/Library/Python/3.9/lib/python/site-packages/urllib3/connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "/Users/user/Library/Python/3.9/lib/python/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.webucator.com', port=443): Max retries exceeded with url: /how-to/address-by-bill-clinton-1997.cfm (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/folders/pz/mf7h9hjd63q940q4kr31l7c00000gp/T/ipykernel_6591/2348624285.py", line 22, in test_set_content_to_tag
ta.set_content_to_tag('div','content-main')
File "/var/folders/pz/mf7h9hjd63q940q4kr31l7c00000gp/T/ipykernel_6591/2563368935.py", line 32, in set_content_to_tag
r = requests.get(self.src)
File "/Users/user/Library/Python/3.9/lib/python/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/Users/user/Library/Python/3.9/lib/python/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/user/Library/Python/3.9/lib/python/site-packages/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/Users/user/Library/Python/3.9/lib/python/site-packages/requests/sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "/Users/user/Library/Python/3.9/lib/python/site-packages/requests/adapters.py", line 517, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.webucator.com', port=443): Max retries exceeded with url: /how-to/address-by-bill-clinton-1997.cfm (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))
Related
I am trying to upload data to google sheet by python.
But i found that I have to use administrator to run the script.
My computer OS is Window10.
The followings are my python script.
import gspread
from google.oauth2.service_account import Credentials
scopes = ["https://www.googleapis.com/auth/spreadsheets"]
credentials = Credentials.from_service_account_file(filename='C:/Users/KCL47/Desktop/googleSheetUpdate/credentials.json', scopes=scopes)
client = gspread.authorize(credentials)
sheet = client.open_by_key("1DjCtgGxJapLNI44KMppmJZGCMjMVLgjmT__3xPdE0Sk").sheet1
sheet.clear()
sheet.append_row(values=header)
sheet.append_rows(values=records)
The file credentials.json, I follow this website to create the json file.
My Python version is 3.10.6.
Most of Library are updated to latest version.
When I use administrator to run the script, there are no any problems.
But when I use normal user to run the script.I got the following Error.
Traceback (most recent call last):
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Python\lib\ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "C:\Python\lib\ssl.py", line 1071, in _create
self.do_handshake()
File "C:\Python\lib\ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\connectionpool.py", line 815, in urlopen
return self.urlopen(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\connectionpool.py", line 815, in urlopen
return self.urlopen(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\connectionpool.py", line 815, in urlopen
return self.urlopen(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\google\auth\transport\requests.py", line 193, in __call__
response = self.session.request(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\requests\adapters.py", line 563, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')))
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\KCL47\Desktop\googleSheetUpdate\updateGoogleSheet.py", line 58, in <module>
sheet = client.open_by_key("1VakExMG9DNG4bKaQk9_2zHCRg-cd3_V-ypdHboE1zsk").sheet1
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\gspread\client.py", line 164, in open_by_key
return Spreadsheet(self, {"id": key})
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\gspread\spreadsheet.py", line 33, in __init__
metadata = self.fetch_sheet_metadata()
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\gspread\spreadsheet.py", line 253, in fetch_sheet_metadata
r = self.client.request("get", url, params=params)
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\gspread\client.py", line 73, in request
response = getattr(self.session, method)(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\requests\sessions.py", line 600, in get
return self.request("GET", url, **kwargs)
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\google\auth\transport\requests.py", line 545, in request
self.credentials.before_request(auth_request, method, url, request_headers)
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\google\auth\credentials.py", line 133, in before_request
self.refresh(request)
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\google\oauth2\service_account.py", line 410, in refresh
access_token, expiry, _ = _client.jwt_grant(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\google\oauth2\_client.py", line 217, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\google\oauth2\_client.py", line 185, in _token_endpoint_request
response_status_ok, response_data = _token_endpoint_request_no_throw(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\google\oauth2\_client.py", line 124, in _token_endpoint_request_no_throw
response = request(
File "C:\Users\KCL47\Desktop\googleSheetUpdate\venv\lib\site-packages\google\auth\transport\requests.py", line 199, in __call__
six.raise_from(new_exc, caught_exc)
File "<string>", line 3, in raise_from
google.auth.exceptions.TransportError: HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')))
This problem appear on sheet = client.open_by_key("1DjCtgGxJapLNI44KMppmJZGCMjMVLgjmT__3xPdE0Sk").sheet1
I have try to update certifi. But It is the latest version already.
The Python is install by administrator user.
How can I run this script without administrator in my computer?
Is it possible that the connection to google is not possible due to proxy settings?
Have you tried adding session?
Example:
import requests
from gspread import Client
session = requests.Session()
session.verify = False
gc = Client(None, session)
gspread doc example:
import json
from gspread import Client
from authlib.integrations.requests_client import AssertionSession
def create_assertion_session(conf_file, scopes, subject=None):
with open(conf_file, 'r') as f:
conf = json.load(f)
token_url = conf['token_uri']
issuer = conf['client_email']
key = conf['private_key']
key_id = conf.get('private_key_id')
header = {'alg': 'RS256'}
if key_id:
header['kid'] = key_id
# Google puts scope in payload
claims = {'scope': ' '.join(scopes)}
return AssertionSession(
grant_type=AssertionSession.JWT_BEARER_GRANT_TYPE,
token_url=token_url,
issuer=issuer,
audience=token_url,
claims=claims,
subject=subject,
key=key,
header=header,
)
scopes = [
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive',
]
session = create_assertion_session('your-google-conf.json', scopes)
gc = Client(None, session)
wks = gc.open("Where is the money Lebowski?").sheet1
wks.update_acell('B2', "it's down there somewhere, let me take another look.")
# Fetch a cell range
cell_list = wks.range('A1:B7')
I have been working on some scripts in python and on https connections I get issue of SSL certificates, especially the self-signed ones. Those are easily over come this particular issue I have with one server is off too weak certificate. Now the server is known to me but not owned by me so I cannot change the certificate. Is there a way to overcome this? I am using a Macbook and the library is an SDK of Solarwinds
Traceback (most recent call last):
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/urllib3/connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/urllib3/connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 453, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 495, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1071, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: EE certificate key too weak (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='10.1.6.200', port=17778): Max retries exceeded with url: /SolarWinds/InformationService/v3/Json/Query (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: EE certificate key too weak (_ssl.c:997)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/networkautomator/VENV/sdkorion/query_test_2.py", line 14, in <module>
results = swis.query("SELECT NodeID, DisplayName, NodeDescription FROM Orion.Nodes Where SysName LIKE 'VELO%'")
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/orionsdk/swisclient.py", line 23, in query
return self._req(
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/orionsdk/swisclient.py", line 52, in _req
resp = self._session.request(method,
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/Users/networkautomator/VENV/sdkorion/lib/python3.10/site-packages/requests/adapters.py", line 563, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='10.20.5.1', port=17778): Max retries exceeded with url: /SolarWinds/InformationService/v3/Json/Query (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: EE certificate key too weak (_ssl.c:997)')))
All help regarding this will be appreciated.
Thanks
When I run my program that uses the requests module to send info to an api, I get the error:
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.fast2sms.com', port=443): Max retries exceeded with url: /dev/bulkV2?authorization=vQWJE07LzxhrR8TM1lDBUK6gASOPy4miVnkf3bHXGZNs9YcI2o3GScblwJY7kmx1rpDWuBnLhVH54vKC&sender_id=TXTIND&route=v3&language=unicode&numbers=14372341004&message=FastSMS+test%0A (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
I've gotten this error before when using requests, I just never tried to fix it.
Full error code:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
conn.connect()
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create
self.do_handshake()
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 440, in send
resp = conn.urlopen(
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.fast2sms.com', port=443): Max retries exceeded with url: /dev/bulkV2?authorization=vQWJE07LzxhrR8TM1lDBUK6gASOPy4miVnkf3bHXGZNs9YcI2o3GScblwJY7kmx1rpDWuBnLhVH54vKC&sender_id=TXTIND&route=v3&language=unicode&numbers=14372341004&message=FastSMS+test%0A (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "c:\Users\user1\AppData\Local\Temp\Temp1_Pythonista_ForAll-main.zip\Pythonista_ForAll-main\SMS_Sender\SMSAutomation.py", line 25, in btn_clk
r = send_sms(num,msg)
File "c:\Users\user1\AppData\Local\Temp\Temp1_Pythonista_ForAll-main.zip\Pythonista_ForAll-main\SMS_Sender\SMSAutomation.py", line 17, in send_sms
response = requests.get(url, params=prams)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 517, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.fast2sms.com', port=443): Max retries exceeded with url: /dev/bulkV2?authorization=vQWJE07LzxhrR8TM1lDBUK6gASOPy4miVnkf3bHXGZNs9YcI2o3GScblwJY7kmx1rpDWuBnLhVH54vKC&sender_id=TXTIND&route=v3&language=unicode&numbers=14372341004&message=FastSMS+test%0A (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
I want to run these 3 commands:
import requests
result = requests.get("https://somedomain.xyz/start_page.html")
print(result.status_code)
but I get an error output:
Traceback (most recent call last):
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn
conn.connect()
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 362, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\ssl_.py", line 386, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1108)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\retry.py", line 446, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='somedomain.xyz', port=443): Max retries exceeded with url: /bzo/en/start_page.html (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1108)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python\TTNr.py", line 8, in
result = requests.get("https://somedomain.xyz/start_page.html")
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "C:\Users\usik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='somedomain.xyz', port=443): Max retries exceeded with url: /start_page.html (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1108)')))
Does anyone know what could be a problem and how to solve it? Thanks in advance.
import requests
result = requests.get("https://somedomain.xyz/start_page.html", verify=False)
print(result.status_code)
If you don't want to keep verify=False, then the path of the relevant certs need to be mentioned here.
You seem to be accessing a site that uses a self-signed certificate. That will not be considered valid by default.
Have a look at: How to get Python requests to trust a self signed SSL certificate?
When using the python 3 Wikipedia module I get an SSL Certificate error. When is use set StrictSSL false the module works but I don't to do that permanently.
I was wondering if there was something I could change,I saw someone using a verify thing but I'm unsure how.
I am also not on a businesses wifi or anything, I think it is something to do with my computer or the actual code?
Here is the code:
outputs = wikipedia.summary(wikiSearch, sentences=3m)
Here is the error:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 350, in connect
ssl_context=context)
File "/usr/local/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 355, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='en.wikipedia.org', port=443): Max retries exceeded with url: /w/api.php?list=search&srprop=&srlimit=1&limit=1&srsearch=alex&srinfo=suggestion&format=json&action=query (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "dave.py", line 42, in <module>
index()
File "dave.py", line 25, in index
outputs = wikipedia.summary(wikiSearch, sentences=3)
File "/usr/local/lib/python3.7/site-packages/wikipedia/util.py", line 28, in __call__
ret = self._cache[key] = self.fn(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/wikipedia/wikipedia.py", line 231, in summary
page_info = page(title, auto_suggest=auto_suggest, redirect=redirect)
File "/usr/local/lib/python3.7/site-packages/wikipedia/wikipedia.py", line 270, in page
results, suggestion = search(title, results=1, suggestion=True)
File "/usr/local/lib/python3.7/site-packages/wikipedia/util.py", line 28, in __call__
ret = self._cache[key] = self.fn(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/wikipedia/wikipedia.py", line 103, in search
raw_results = _wiki_request(search_params)
File "/usr/local/lib/python3.7/site-packages/wikipedia/wikipedia.py", line 737, in _wiki_request
r = requests.get(API_URL, params=params, headers=headers)
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 668, in send
history = [resp for resp in gen] if allow_redirects else []
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 668, in <listcomp>
history = [resp for resp in gen] if allow_redirects else []
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 247, in resolve_redirects
**adapter_kwargs
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='en.wikipedia.org', port=443): Max retries exceeded with url: /w/api.php?list=search&srprop=&srlimit=1&limit=1&srsearch=alex&srinfo=suggestion&format=json&action=query (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))
I hope someone can help! :)