Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CERTIFICATE_VERIFY_FAILED #40

Closed
cristian5th opened this issue May 28, 2020 · 7 comments
Closed

CERTIFICATE_VERIFY_FAILED #40

cristian5th opened this issue May 28, 2020 · 7 comments

Comments

@cristian5th
Copy link
Contributor

Hello all.

I'm finding an SSL certificate issue only when executing the script with Python 3. If I execute it with Python 2, then there is no problem at all.

This is the complete error message I'm getting:

[ERROR] Failed to reach url https://sso.garmin.com/sso/signin?service=https%3A%2F%2Fconnect.garmin.com%2Fmodern%2F&webhost=https%3A%2F%2Fconnect.garmin.com&source=https%3A%2F%2Fconnect.garmin.com%2Fen-US%2Fsignin&redirectAfterAccountLoginUrl=https%3A%2F%2Fconnect.garmin.com%2Fmodern%2F&redirectAfterAccountCreationUrl=https%3A%2F%2Fconnect.garmin.com%2Fmodern%2F&gauthHost=https%3A%2F%2Fsso.garmin.com%2Fsso&locale=en_US&id=gauth-widget&cssUrl=https%3A%2F%2Fstatic.garmincdn.com%2Fcom.garmin.connect%2Fui%2Fcss%2Fgauth-custom-v1.2-min.css&clientId=GarminConnect&rememberMeShown=true&rememberMeChecked=false&createAccountShown=true&openCreateAccount=false&displayNameShown=false&consumeServiceTicket=false&initialFocus=true&embedWidget=false&generateExtraServiceTicket=true&generateTwoExtraServiceTickets=false&generateNoServiceTicket=false&globalOptInShown=true&globalOptInChecked=false&mobile=false&connectLegalTerms=true&locationPromptShown=true&showPassword=true, error: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>
Connecting to Garmin Connect...Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 1016, in _send_output
self.send(msg)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 956, in send
self.connect()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 1392, in connect
server_hostname=server_hostname)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.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 "/Users/cralvarez/Downloads/garmin-connect-export-master/gcexport.py", line 1057, in
main(sys.argv)
File "/Users/cralvarez/Downloads/garmin-connect-export-master/gcexport.py", line 859, in main
login_to_garmin_connect(args)
File "/Users/cralvarez/Downloads/garmin-connect-export-master/gcexport.py", line 494, in login_to_garmin_connect
connect_response = http_req_as_string(URL_GC_LOGIN)
File "/Users/cralvarez/Downloads/garmin-connect-export-master/gcexport.py", line 271, in http_req_as_string
return http_req(url, post, headers).decode()
File "/Users/cralvarez/Downloads/garmin-connect-export-master/gcexport.py", line 247, in http_req
response = OPENER.open(request, data=post)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, 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:1056)>

I wonder if the issue could be because of some module dependency that I'm missing in Python 3.

Somebody has any idea about how to proceed?

Thank you. Best regards.

@pEwenM
Copy link

pEwenM commented May 28, 2020

I had that after installing Python3 - I needed to import the SSL certificates locally (via batch script that came with the Python3 release) and then it worked fine

@pe-st
Copy link
Owner

pe-st commented May 28, 2020

Hello @cristian5th, can you tell the exact Python version? I know there are some SSL problems with older 2.7.x versions (see #16), so maybe there are also differences regarding SSL between different 3.7.x versions?

You can find the exact version with python3 --version or in the log file gcexport.log

@cristian5th
Copy link
Contributor Author

Hi @pe-st

It is Python 3.7.3. To be perfectly clear, it is the Python version that comes with Mac OS Catalina. I mean, they must come both preinstalled, 2.7.16 and 3.7.3, because I havent installed none of them and here they are both. Unless the version 3 was installed via another software and I didn't noticed.

@pEwenM , can you elaborate on the certificate import script that you are talking about? Where should I go look for it?

Thank you.

@pEwenM
Copy link

pEwenM commented May 28, 2020

@cristian5th I'm also on MacOS. Googling directed me to
Applications > Python 3.8 > Install Certificates.command
I ran that which solved the issue. I assume there's the same in 3.7 but don't have that installed so cannot check.
Ewen.

@cristian5th
Copy link
Contributor Author

Hmmm. Something strange is happening here @pEwenM

I do not have a Python3 folder. The executable is found directly under /usr/bin/python3, and there is nothing similar to what you mention.

I will investigate the Catalina clue. This must be something done by Apple.

@pEwenM
Copy link

pEwenM commented May 28, 2020

@cristian5th I'm on Catalina 10.15.4 and installed Python 3.8 myself via the GUI not terminal command line. I've got the executable in /usr/bin/python3 like you, but I also have /Applications/Python 3.8/Install Certificates.command which I ran to resolve the issue.

@cristian5th
Copy link
Contributor Author

@pEwenM, I haven't installed Python 3.7. It already came with Catalina and I am missing the Python copy that you have at the Applications folder, and therefore I don't have the Install Certificates.command that you have.

I have been looking around and it seems that the Python 3.7 being delivered with Catalina is not the real thing. I cannot explain what is missing but it seems to me that many dependencies are missing.

I ended up installing Python 3.8.2 and the garmin-connect-export script is now working like a charm out of the box. I didn't had to import any certificate locally.

Consequently, this was not a real issue from the script. Thanks all for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants