Closed dkanze closed 8 hours ago
Hi Dan!
So it looks like the error you are getting is related to SSL. Can you update the Wordnik api url to https://api.wordnik.com/v4 and see if that fixes it?
Thanks for using Wordnik!
Yours,
Erin McKean Wordnik @@.**@.@wordnik.social Wordnik is a 501(c)3 nonprofit organization The Wordnik mission: every English word, available to everyone, everywhere
On Wed, Nov 13, 2024 at 5:39 PM dkanze @.***> wrote:
I just signed up for a wordnik api key. I took a small example to try using Python3.
I tried calling the api diretly from a browser and got valid replies using my API key. I then coped an example from the wordnik site. It generated the errors listed below.
I am wondering what I am doing wrong. Perhaps someone has an example I could clone?
Thanks Dan
from wordnik import * apiUrl = 'http://api.wordnik.com/v4' apiKey = 'MY API KEY REMOVED FOR THIS POSTING' client = swagger.ApiClient(apiKey, apiUrl)
wordApi = WordApi.WordApi(client) example = wordApi.getTopExample('irony') print(example.text) This generated the following error.... /Users/dkanze/PycharmProjects/pythonProject2/.venv/bin/python /Users/dkanze/Library/Application Support/JetBrains/PyCharmCE2024.2/scratches/scratch_14.py Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 1319, in do_open h.request(req.get_method(), req.selector, req.data, headers,
~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ encode_chunked=req.has_header('Transfer-encoding')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1336, in request self._send_request(method, url, body, headers, encode_chunked)"/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1382, in _send_request self.endheaders(body, encode_chunked=encode_chunked) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1331, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1091, in _send_output self.send(msg) ~~~~~~~~~^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1035, in send self.connect() ~~~~~~~~~~~~^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1477, in connect self.sock = self._context.wrap_socket(self.sock, ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^ server_hostname=server_hostname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 455, in wrap_socket return self.sslsocket_class._create( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ sock=sock, ^^^^^^^^^^ ...<5 lines>... session=session ^^^^^^^^^^^^^^^ ) ^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1076, in _create self.do_handshake() ~~~~~~~~~~~~~~~~~^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1372, in do_handshake self._sslobj.do_handshake() ~~~~~~~~~~~~~~~~~~~~~~~~~^^ ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1020) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/dkanze/Library/Application Support/JetBrains/PyCharmCE2024.2/scratches/scratch_14.py", line 7, in example = wordApi.getTopExample('irony') File "/Users/dkanze/PycharmProjects/pythonProject2/.venv/lib/python3.13/site-packages/wordnik/WordApi.py", line 225, in getTopExample response = self.apiClient.callAPI(resourcePath, method, queryParams, postData, headerParams) File "/Users/dkanze/PycharmProjects/pythonProject2/.venv/lib/python3.13/site-packages/wordnik/swagger.py", line 73, in callAPI request = urllib.request.urlopen(requestParams) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 189, in urlopen return opener.open(url, data, timeout) ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 495, in open response = meth(req, response) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 604, in http_response response = self.parent.error( 'http', request, response, code, msg, hdrs) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 527, in error result = self._call_chain(*args) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 466, in _call_chain result = func(*args) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 720, in http_error_302 return self.parent.open(new, timeout=req.timeout) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 489, in open response = self._open(req, data) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 506, in _open result = self._call_chain(self.handle_open, protocol, protocol + '_open', req) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 466, in _call_chain result = func(*args) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 1367, in https_open return self.do_open(http.client.HTTPSConnection, req, ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ context=self._context) ^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 1322, 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:1020)> Process finished with exit code 1 — Reply to this email directly, view it on GitHub <https://github.com/wordnik/wordnik-python3/issues/15>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AABXBGIUEKIT7LA46FP75J32AP5L3AVCNFSM6AAAAABRXZGFP6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGY2TOMRWGIZDQNY> . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
I tried using https and got the same error. Does the same code work for you? I am running the code in PyCharm.
Thanks Dan
Fixed
I needed to do one thing.
I am running MacOS so I had to run the install certificate command in the python application folder.
Works!
I just signed up for a wordnik api key. I took a small example to try using Python3.
I tried calling the api diretly from a browser and got valid replies using my API key. I then coped an example from the wordnik site. It generated the errors listed below.
I am wondering what I am doing wrong. Perhaps someone has an example I could clone?
Thanks Dan
from wordnik import * apiUrl = 'http://api.wordnik.com/v4' apiKey = 'MY API KEY REMOVED FOR THIS POSTING' client = swagger.ApiClient(apiKey, apiUrl)
wordApi = WordApi.WordApi(client) example = wordApi.getTopExample('irony') print(example.text) This generated the following error.... /Users/dkanze/PycharmProjects/pythonProject2/.venv/bin/python /Users/dkanze/Library/Application Support/JetBrains/PyCharmCE2024.2/scratches/scratch_14.py Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 1319, in do_open h.request(req.get_method(), req.selector, req.data, headers,
~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ encode_chunked=req.has_header('Transfer-encoding')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1336, in request self._send_request(method, url, body, headers, encode_chunked) ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1382, in _send_request self.endheaders(body, encode_chunked=encode_chunked)~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1331, in endheaders self._send_output(message_body, encode_chunked=encode_chunked)~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1091, in _send_output self.send(msg) ~~~^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1035, in send self.connect()~~^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1477, in connect self.sock = self._context.wrap_socket(self.sock, ~~~~~^^^^^^^^^^^ server_hostname=server_hostname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 455, in wrap_socket return self.sslsocket_class._create( ~~~~~~^ sock=sock, ^^^^^^^^^^ ...<5 lines>... session=session ^^^^^^^^^^^^^^^ ) ^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1076, in _create self.do_handshake()~~~^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1372, in do_handshake self._sslobj.do_handshake() ~~~~~~~^^ ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1020)During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/dkanze/Library/Application Support/JetBrains/PyCharmCE2024.2/scratches/scratch_14.py", line 7, in example = wordApi.getTopExample('irony') File "/Users/dkanze/PycharmProjects/pythonProject2/.venv/lib/python3.13/site-packages/wordnik/WordApi.py", line 225, in getTopExample response = self.apiClient.callAPI(resourcePath, method, queryParams, postData, headerParams) File "/Users/dkanze/PycharmProjects/pythonProject2/.venv/lib/python3.13/site-packages/wordnik/swagger.py", line 73, in callAPI request = urllib.request.urlopen(requestParams) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 189, in urlopen return opener.open(url, data, timeout)
~~~^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 495, in open response = meth(req, response) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 604, in http_response response = self.parent.error( 'http', request, response, code, msg, hdrs) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 527, in error result = self._call_chain(args) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 466, in _call_chain result = func(args) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 720, in http_error_302 return self.parent.open(new, timeout=req.timeout)~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 489, in open response = self._open(req, data) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 506, in _open result = self._call_chain(self.handle_open, protocol, protocol + '_open', req) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 466, in _call_chain result = func(*args) File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 1367, in https_open return self.do_open(http.client.HTTPSConnection, req,~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ context=self._context) ^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/urllib/request.py", line 1322, 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:1020)>Process finished with exit code 1