In python, I am trying to use the copyleaks API to authenticate/obtain my authentication token:
from copyleaks.copyleaks import Copyleaks
from copyleaks.exceptions.command_error import CommandError
# Register on https://api.copyleaks.com and grab your secret key (from the dashboard page).
EMAIL_ADDRESS = 'my_email'
KEY = 'my_key'
try:
auth_token = Copyleaks.login(EMAIL_ADDRESS, KEY)
except CommandError as ce:
response = ce.get_response()
print(f"An error occurred (HTTP status code {response.status_code}):")
print(response.content)
exit(1)
print("Logged successfully!\nToken:")
print(auth_token)
However, after running the code above in pycharm, I get the following error message below:
Traceback (most recent call last):
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
conn.connect()
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\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\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 501, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1041, in _create
self.do_handshake()
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1310, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
retries = retries.increment(
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='id.copyleaks.com', port=443): Max retries exceeded with url: /v3/account/login/api (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hans.miguel.prieto\OneDrive - Accenture\Documents\Projects\AWS Lex - Project Neo\Copyleaks API Python Test\copyleaks_test.py", line 15, in <module>
auth_token = Copyleaks.login(EMAIL_ADDRESS, KEY)
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\copyleaks\copyleaks.py", line 91, in login
response = requests.post(url, headers=headers, data=json.dumps(payload))
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 115, in post
return request("post", url, data=data, json=json, **kwargs)
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "C:\Users\hans.miguel.prieto\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 563, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='id.copyleaks.com', port=443): Max retries exceeded with url: /v3/account/login/api (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)')))
This is the SSL Error that I get at the end:
requests.exceptions.SSLError: HTTPSConnectionPool(host='id.copyleaks.com', port=443): Max retries exceeded with url: /v3/account/login/api (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1129)')))
The following code works perfectly on Google Colab, but on Pycharm, it seems there are some issues verifying the ssl certificate. What are some solutions to fix this problem, so that it can work in Pycharm? I am using a work laptop, and I am not an a VPN or any type of proxy.