I Cant Use Pyngrok(certificate verify failed: certificate has expired) - python

I can't Use Pyngrok
Every time I run a script with the module pyngrok it displays the error:
Downloading ngrok ...
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1348, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1037, in _send_output
self.send(msg)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 975, in send
self.connect()
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1454, in connect
self.sock = self._context.wrap_socket(self.sock,
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create
self.do_handshake()
File "C:\Users\hp\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: certificate has expired (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\pyngrok\installer.py", line 94, in install_ngrok
download_path = _download_file(url, **kwargs)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\pyngrok\installer.py", line 215, in _download_file
response = urlopen(url, **kwargs)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 519, in open
response = self._open(req, data)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
result = func(*args)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\server1.py", line 12, in <module>
public_url = ngrok.connect(port, "tcp", options={"remote_addr": "{}:{}".format(host, port)})
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\pyngrok\ngrok.py", line 251, in connect
api_url = get_ngrok_process(pyngrok_config).api_url
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\pyngrok\ngrok.py", line 160, in get_ngrok_process
install_ngrok(pyngrok_config)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\pyngrok\ngrok.py", line 98, in install_ngrok
installer.install_ngrok(pyngrok_config.ngrok_path)
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\site-packages\pyngrok\installer.py", line 98, in install_ngrok
raise PyngrokNgrokInstallError("An error occurred while downloading ngrok from {}: {}".format(url, e))
pyngrok.exception.PyngrokNgrokInstallError: An error occurred while downloading ngrok from https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-windows-amd64.zip: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)>
Please, Help!
OS: Windows11 Home Single Language
Cpu: Intel i5
python version:3.10.2(I Tried it on 3.9.7 too)
I even tried updating python and my os but it won't work!
[SSL: CERTIFICATE_VERIFY_FAILED]

Currently having the same issue, one way is to use pyopenssl
import requests
import json
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import ssl
class MyAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
ssl_version=ssl.PROTOCOL_TLSv1_2)
url = 'https://example.com'
data = {'key': 'value'}
session = requests.Session()
session.mount('https://', MyAdapter())
response = session.post(url, data=json.dumps(data))
but I wouldn't recommend because you're not using ssl auth

Related

Getting error when trying to use fredapi in python

I am trying to simply use the fredapi to pull a series from FRED text but I am getting an error.
I'm guessing the issue is with the API key but not sure.
Here is the code I executed
import pandas as pd
from fredapi import Fred
# Replace YOUR_API_KEY with your FRED API key
api_key = 'my_key'
# Create a FRED API instance using your API key
fred = Fred(api_key = api_key)
# Extract the series data from FRED
series_data = fred.get_series('SP500')
# Print the series data
print(series_data)
Here is the error I got:
/Users/PycharmProjects/Email/venv/bin/python /Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 49337 --file /Users/PycharmProjects/Email/main.py
Connected to pydev debugger (build 223.8214.51)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 1348, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1037, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 975, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1454, in connect
self.sock = self._context.wrap_socket(self.sock,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 517, in wrap_socket
return self.sslsocket_class._create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1075, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1346, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/PycharmProjects/Email/venv/lib/python3.11/site-packages/fredapi/fred.py", line 64, in __fetch_data
response = urlopen(url)
^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 519, in open
response = self._open(req, data)
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 496, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)>
python-BaseException
Process finished with exit code 1

Why python can not run wget?

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import os
import wget
PATH = "/Users/kaikeichan/Downloads/chromedriver"
driver = webdriver.Chrome(PATH)
driver.get("https://www.instagram.com/")
username = WebDriverWait(driver,10).until(
EC.presence_of_element_located((By.NAME,"username"))
)
password = WebDriverWait(driver,10).until(
EC.presence_of_element_located((By.NAME,"password"))
)
login = driver.find_element_by_xpath('//*[#id="loginForm"]/div/div[3]')
username.clear()
password.clear()
username.send_keys('learntocodeztm')
password.send_keys('929kai927')
login.click()
search = WebDriverWait(driver,10).until(
EC.presence_of_element_located((By.XPATH,'//*[#id="react-root"]/section/nav/div[2]/div/div/div[2]/input'))
)
keyword = "#cat"
search.send_keys(keyword)
time.sleep(1)
search.send_keys(Keys.RETURN)
time.sleep(1)
search.send_keys(Keys.RETURN)
WebDriverWait(driver,10).until(
EC.presence_of_element_located((By.CLASS_NAME,"FFVAD"))
)
imgs = driver.find_elements_by_class_name("FFVAD")
path = os.path.join(keyword)
os.mkdir(path)
count = 0
for img in imgs:
save_as = os.path.join(path, keyword + str(count) + '.jpg')
# print(img.get_attribute("src"))
wget.download(img.get_attribute("src"), save_as)
count += 1
terminal error message
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1350, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1240, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1286, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1235, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1006, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 946, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1409, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/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:1108)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ig.py", line 57, in <module>
wget.download(img.get_attribute("src"), save_as)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/wget.py", line 526, in download
(tmpfile, headers) = ulib.urlretrieve(binurl, tmpfile, callback)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 247, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1393, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1353, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
Why python can not run wget?
Your traceback clearly shows that there is some problem with SSL certificate
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
and
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)
You are using wget.download function from wget which as far as I know does not offer easy way to turn off verification.

error [SSL: CERTIFICATE_VERIFY_FAILED] when running 'earthengine authenticate'

I am trying to authorize access to Earth Engine via earthengine authenticate but get the following error:
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 1350, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1010, in _send_output
self.send(msg)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 950, in send
self.connect()
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\http\client.py", line 1424, in connect
self.sock = self._context.wrap_socket(self.sock,
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\ssl.py", line 1040, in _create
self.do_handshake()
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\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:1124)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\Scripts\earthengine-script.py", line 9, in <module>
sys.exit(main())
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\cli\eecli.py", line 84, in main
_run_command()
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\cli\eecli.py", line 63, in _run_command
dispatcher.run(args, config)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\cli\commands.py", line 353, in run
self.command_dict[vars(args)[self.dest]].run(args, config)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\cli\commands.py", line 386, in run
ee.Authenticate(**args_auth)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\__init__.py", line 86, in Authenticate
oauth.authenticate(authorization_code, quiet, code_verifier)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\oauth.py", line 233, in authenticate
_obtain_and_write_token(None, code_verifier) # Will prompt for auth_code.
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\oauth.py", line 139, in _obtain_and_write_token
token = request_token(auth_code.strip(), code_verifier)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\site-packages\ee\oauth.py", line 82, in request_token
response = request.urlopen(
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 1393, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "C:\Users\jwiesehahn\Anaconda3\envs\treespecies\lib\urllib\request.py", line 1353, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1124)>
Otherwise I have access to Earth Engine.
I am running this in a new conda environment with Python 3.8.1.
Running it with Python 3.6.1 results in a similar error ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852).
And running this on a different maschine does not result in errors.
Do you have any ideas?

Wolfram Alpha Python: SSL: CERTIFICATE_VERIFY_FAILED error

I have been trying to run this simple code snippet to check my installation of Wolfram Alpha on Python.
This is the code I have been trying to run:
import ssl
import wolframalpha
app_id = "*****************"
client = wolframalpha.Client(app_id)
my_input = input("Question: ")
res = client.query(my_input)
answer = next(res.results).text
print(answer)
This is the error I have been facing
Traceback (most recent call last):
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 964, in send
self.connect()
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1400, in connect
server_hostname=server_hostname)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 817, in __init__
self.do_handshake()
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\MARIA\TEST_walpha.py", line 6, in <module>
res = client.query(my_input)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wolframalpha\__init__.py", line 53, in query
resp = urllib.request.urlopen(url)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)>
Now I consulted this post, but there was no clear answer provide, and importing the SSL library did not solve my problem.
You can try disabling certificate verification globally by doing something like this:
ssl._create_default_https_context = ssl._create_unverified_context

UnificationEngine: Unable to send Requests via Python using TLS or SSL

I am attempting to use a Raspberry Pi 3 (Model B) to send Requests by Python to the Unification Engine. With SSL/TLS verification disabled, the request happens normally, but I need to get SSL/TLS working with it.
The below code is meant to force a session to use TLSv1 for the purpose of sending Python Requests to UnificationEngine:
class ForceTLSV1Adapter(HTTPAdapter):
def init_poolmanager(self, connection, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connection,maxsize=maxsize,block=block,ssl_version=ssl.PROTOCOL_TLSv1)
def proxy_manager_for(self, proxy, **proxy_kwargs):
proxy_kwargs['ssl_version'] = ssl.PROTOCOL_TLSv1
return super(ForceTLVS1Adapter, self).proxy_manager_for(proxy, **proxy_kwargs)
----Some Code here----
s = requests.Session()
s.mount('https://apiv2.unificationengine.com', ForceTLSV1Adapter())
----Some Code Here----
However, this error pops up after I send the request.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 516, in urlopen
body=body, headers=headers)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 304, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 724, in _validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 237, in connect
ssl_version=resolved_ssl_version)
File "/usr/lib/python3/dist-packages/urllib3/util/ssl_.py", line 123, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3.4/ssl.py", line 364, in wrap_socket
_context=self)
File "/usr/lib/python3.4/ssl.py", line 577, in __init__
self.do_handshake()
File "/usr/lib/python3.4/ssl.py", line 804, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 362, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 543, in urlopen
raise SSLError(e)
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Documents/HumidityRequest.py", line 134, in <module>
sendEmail(round(temp,3))
File "/home/pi/Documents/HumidityRequest.py", line 92, in sendEmail
r = requests.post('https://apiv2.unificationengine.com/v2/message/send', auth=(key,secret),data=userMessage)
File "/usr/lib/python3/dist-packages/requests/api.py", line 94, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 49, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 420, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
I'm not sure what is the issue right now.
Looks like the certificate verification isn't done correctly.
Have a look at:
https://the.randomengineer.com/2014/01/29/using-ssl-wrap_socket-for-secure-sockets-in-python/
https://urllib3.readthedocs.io/en/latest/user-guide.html#ssl
you could also try the httplib.

Categories

Resources