Closed pgshow closed 2 years ago
Understand, My VPN issue. It totally works on a cloud server.
👌
Hey where you able to fix the issue?
Hey where you able to fix the issue?
Don't use a Proxy or VPN, use the script on aws cloud server, and it may work.
I am having issues with sending myself emails using yagmail with the use of the OAuth2 verification. Here’s the code snippet: def send_mail(): gmail = os.environ.get("GMAIL") gmail_pass = os.environ.get("GMAIL_PASS")
yag = yagmail.SMTP("[arifurrahman@nypl.org](mailto:arifurrahman@nypl.org)",oauth2_file="./oauth2_creds.json")
# contents = ['This is the body, and here is just text',
# 'You can find an audio file attached.', '/local/path/song.mp3']
yag.send(subject="Great success Wawa Wee Wa!”)
The function runs and obtains my credentials from my json file ; however when I paste in the link that it tells me to go to, after allowing the app to do its thing, I get a black screen saying localhost refused to connect. As stated in the console I just take the localhost url at the top which contains the code param needed to continue on with the script as :”http://localhost/?code=….a&scope=https://mail.google.com/“, and paste it in the console, and then get a massive error as such:
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/arah/spotlight/spot.py", line 165, in
Pertaining to to some SSL certificate error which may because the localhost refused to connect, which I’m not entirely sure how to fix. I checked my console.cloud.google account to make sure the oauth2.0 client ids are for a desktop app. I made the internal for the user type, but that doesn’t as matter as much because I am pasting the link on the google account that has access. I checked with to see if that was an issue by using a different email, but it gave me a 403 error which is expected as that gmail is not in the org I set internally. I also kept the authorized app domain fields blank and just gave the app a name and user support email and developer contact info, which is the bare necessity to make Oauth consent screen work. I am also using
I realized how you can fix the SSL error and all you need is this line: ssl._create_default_https_context = ssl._create_unverified_context
and import ssl in the code. I hope this helps anyone for those using oauth2 with yagmail
When I tried to use Gmail auth2.0 for yagmail.
When I use python3.7, the error is
self._sslobj.do_handshake() OSError: [Errno 0] Error
When I use python3.8, the error becomes.
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1131)