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
Related
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
It seems that pandas is acting differently when trying to read a CSV from the web between Python 3.8 and Python 3.10. It works with 3.8, but appears to fail with 3.10.
I am using the call:
w1 = pd.read_csv("https://www.ncei.noaa.gov/data/local-climatological-data/access/2021/72254013904.csv")
To try to download weather data from the NOAA website. It works with Python 3.8:
But the same thing fails with Python 3.10:
The full error output is here:
>>> w1 = pd.read_csv("https://www.ncei.noaa.gov/data/local-climatological-data/access/2021/72254013904.csv", low_memory=False)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/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.10/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1454, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1070, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/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 "<stdin>", line 1, in <module>
File "/Users/jrhodes/Library/Python/3.10/lib/python/site-packages/pandas/util/_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "/Users/jrhodes/Library/Python/3.10/lib/python/site-packages/pandas/io/parsers/readers.py", line 680, in read_csv
return _read(filepath_or_buffer, kwds)
File "/Users/jrhodes/Library/Python/3.10/lib/python/site-packages/pandas/io/parsers/readers.py", line 575, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/Users/jrhodes/Library/Python/3.10/lib/python/site-packages/pandas/io/parsers/readers.py", line 933, in __init__
self._engine = self._make_engine(f, self.engine)
File "/Users/jrhodes/Library/Python/3.10/lib/python/site-packages/pandas/io/parsers/readers.py", line 1217, in _make_engine
self.handles = get_handle( # type: ignore[call-overload]
File "/Users/jrhodes/Library/Python/3.10/lib/python/site-packages/pandas/io/common.py", line 670, in get_handle
ioargs = _get_filepath_or_buffer(
File "/Users/jrhodes/Library/Python/3.10/lib/python/site-packages/pandas/io/common.py", line 339, in _get_filepath_or_buffer
with urlopen(req_info) as req:
File "/Users/jrhodes/Library/Python/3.10/lib/python/site-packages/pandas/io/common.py", line 239, in urlopen
return urllib.request.urlopen(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 519, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/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:997)>
Did something change in the SSL perhaps between 3.8 and 3.10?
I've just run into this too. There is indeed increased security in Python 3.10. I've opened a bug report, but in the meantime a workaround based on this post is:
import ssl
from urllib.request import urlopen
import pandas as pd
url = ("https://www.ncei.noaa.gov/"
"data/local-climatological-data/"
"access/2021/72254013904.csv")
context = ssl.create_default_context()
context.set_ciphers("DEFAULT")
result = urlopen(url, context=context)
df = pd.read_csv(result)
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?
I am trying to download youtube video using PyTube package but I am unable to do so.
I am using Python 3.5 and pytube 9.2.2.
Urllib doesn't give me an error in other programs but it is giving me errors here.
The code I am using is:
#importing the module
from pytube import YouTube
#where to save
SAVE_PATH = "E:/" #to_do
#link of the video to be downloaded
link="https://www.youtube.com/watch?v=xWOoBJUqlbI"
yt = YouTube(link)
#filters out all the files with "mp4" extension
mp4files = yt.filter('mp4')
yt.set_filename('GeeksforGeeks Video') #to set the name of the file
#get the video with the extension and resolution passed in the get() function
d_video = yt.get(mp4files[-1].extension,mp4files[-1].resolution)
try:
#downloading the video
d_video.download(SAVE_PATH)
except:
print("Some Error!")
print('Task Completed!')
The errors that I am getting are:
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1240, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1128, in _send_request
self.endheaders(body)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1079, in endheaders
self._send_output(message_body)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 911, in _send_output
self.send(msg)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 854, in send
self.connect()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1237, in connect
server_hostname=server_hostname)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 376, in wrap_socket
_context=self)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 747, in __init__
self.do_handshake()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 983, in do_handshake
self._sslobj.do_handshake()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:646)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "2TryingPyTube.py", line 10, in <module>
yt = YouTube(link)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\__main__.py", line 87, in __init__
self.prefetch_init()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\__main__.py", line 95, in prefetch_init
self.prefetch()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\__main__.py", line 158, in prefetch
self.watch_html = request.get(url=self.watch_url)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\request.py", line 21, in get
response = urlopen(url)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 465, in open
response = self._open(req, data)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 483, in _open
'_open', req)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1283, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1242, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:646)>
I wish someone could help me.
PS - I am only a beginner in using urllib, http packages. Please don't write harsh comments, thank you :0
I'm not advanced at python but its the best coding language I know. I'm doing this challenge that has 5 URLS which change contents every 10 seconds. They each contain part of a code. There is also a validation link which checks the urls I have clicked and checks if it the right code, if it is it will give me a code. So to solve this I'm writing a script that will get all the contents of the 5 URLs and concatenate them together and paste it in the URL of the validation link which will then give me a code which I need.
Here's my code
import urllib.request
fp1 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt1?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes1 = fp1.read()
fp1.close()
fp2 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt2?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes2 = fp2.read()
fp2.close()
fp3 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt3?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes3 = fp3.read()
fp3.close()
fp4 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt4?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes4 = fp4.read()
fp4.close()
fp5 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt5?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
mybytes5 = fp5.read()
fp5.close()
fp6 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/get-flag?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D&string=" + mybytes1 + mybytes2 + mybytes3 + mybytes4 + mybytes5)
mybytes6 = fp6.read()
fp6.close()
print(mybytes6)
However I am getting an error which I don't understand.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/sarvesh/Documents/scriptdis.py", line 3, in <module>
fp1 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt1?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D")
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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:749)>
Can anyone help me understand what's wrong?
urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error
You are trying to open a website without a valid certificate. If you trust the website, then you need to create an uncertified context or urllib will throw the error you are seeing.
import ssl
# This restores the same behavior as before.
context = ssl._create_unverified_context()
fp1 = urllib.request.urlopen("https://assess.joincyberdiscovery.com/challenge-files/clock-pt1?verify=Gl7fPRYxQvgBdbmhMo8vkA%3D%3D", context=context)