I tried to use SMTP in python to send gmail, but it failed - email

here is my script:
from email.mime.text import MIMEText
import smtplib
msg=MIMEText('hi, send by python.....','plain','utf-8')
from_addr='user#gmail.com'
passowrd='psw'
to_addr='user#gmail.com'
s=smtplib.SMTP('smtp.gmail.com',587)
s.login(from_addr,password)
s.sendmail(from_addr, [to_addr], msg.as_string())
when it is running, error occurs:
Traceback (most recent call last):
File "C:\Users\bicuilin\Desktop\begin.py", line 17, in <module>
s.login(from_addr, password)
File "C:\Users\bicuilin\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 696, in login
"SMTP AUTH extension not supported by server.")
smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.
I try to fix it. I add code below:
...
s.ehlo()
s.starttls()
s.login(from_addr, password)
s.sendmail(from_addr, [to_addr], msg.as_string())
s.quit()
here comes out error I really don't understand:
Traceback (most recent call last):
File "C:\Users\bicuilin\Desktop\begin.py", line 20, in <module>
s.login(from_addr, password)
File "C:\Users\bicuilin\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 729, in login
raise last_exception
File "C:\Users\bicuilin\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 720, in login
initial_response_ok=initial_response_ok)
File "C:\Users\bicuilin\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 641, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvK\n5.7.14 1h8JVCjH3EdlnG4ye0St7PIWFsYfjtuO_qovrt6r-spvSMGNbeCxbpXuo3HfqK535dgJy2\n5.7.14 Tjz1zrEZI8QqRc0GyXD2t3Xa0rj_MVHbzX5fM1f2zgbFyoP9YUbwCyaRD5guosxyv3HcS8\n5.7.14 fvB_ORP6_djncJPUwGw98BDCTo2pw3RSvgYHAvS_xO-T97Hw2z35g3AKPW9Bb5E9EcpAgg\n5.7.14 pewpsm0VngKqoxhYhtFwHBW_8s1ig> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 a67sm1686251qkc.24 - gsmtp')

You have to use SMTP_SSL class and it works (tested here). no need to starttls (won't work anyway)
from email.mime.text import MIMEText
import smtplib
msg=MIMEText('hi, send by python.....','plain','utf-8')
from_addr='user#gmail.com'
password='psw'
to_addr='user#gmail.com'
s=smtplib.SMTP_SSL('smtp.gmail.com')
s.login(from_addr,password)
s.sendmail(from_addr, [to_addr], msg.as_string())

Less Secure Apps - gmail
Had the same issue. after allow less secure apps at Gmail, got it working!

Related

Raspberry Pico W network test fails

I just put my hands on RP Pico W to try it out but I hit the issue with the very first wifi test.
Tutorials say to do this:
import network
import socket
from time import sleep
from picozero import pico_temp_sensor, pico_led
import machine
so my pico lib folder looks like this when I imported all required packages:
However when try to run wifi test like this:
def connect():
#Connect to WLAN
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while wlan.isconnected() == False:
print('Waiting for connection...')
sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')
try:
connect()
except KeyboardInterrupt:
machine.reset()
it fails with following error:
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/network.py", line 8, in <module>
File "/lib/socket.py", line 42, in <module>
AttributeError: 'module' object has no attribute 'socket'
>>>
This is whole code, I skipped only ssid and password.
I cannot figure out what exactly is wrong here. I do not have any other files named the same as socket or so.
I took the example from RP foundation pages:
https://projects.raspberrypi.org/en/projects/get-started-pico-w/2

Runing the sample code for google assistant sdk giving SyntaxErorr: invalid syntax

I'm trying to run the following code for starting my google assistant with the raspbery pi:
googlesamples-assistant-pushtotalk --project-id my-dev-project --device-model-id my-model
But I get the following error:
Traceback (most recent call last):
File "/home/pi/env/bin/googlesamples-assistant-pushtotalk", line 5, in <module>
from googlesamples.assistant.grpc.pushtotalk import main
File "/home/pi/env/lib/python3.9/site-packages/googlesamples/assistant/grpc/pushtotalk.py", line 29, in <module>
from tenacity import retry, stop_after_attempt, retry_if_exception
File "/home/pi/env/lib/python3.9/site-packages/tenacity/__init__.py", line 292
from tenacity.async import AsyncRetrying
^
SyntaxError: invalid syntax
Just use:
pip install -U tenacity
Solve for me...

Traceback Errors in Python

Started coding a python program using BeautifulSoup to track GTA V price on Amazon.
Getting these errors:
Traceback (most recent call last):
File "scraper.py", line 68, in <module>
check_price()
File "scraper.py", line 35, in check_price
send_mail()
File "scraper.py", line 50, in send_mail
server.login('sathwikapps#gmail.com', 'Jaybeatx')
File "D:\Users\sathw\anaconda3\lib\smtplib.py", line 697, in login
"SMTP AUTH extension not supported by server.")
smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.
My github repository is : https://github.com/SathwikChiluveru/GTA-V-Price-Tracker
Try to activate on you gmail smtp access for thirdparty :)

Getting error on kubectl get nodes command

I am getting an error while running the following command. I have updated gcloud SDK but still facing same error.
kubectl get nodes
Unable to connect to the server: error executing access token command "/Users/salayhin/google-cloud-sdk/bin/gcloud config config-helper --format=json": err=exit status 1 output= stderr=Traceback (most recent call last):
File "/Users/salayhin/google-cloud-sdk/lib/gcloud.py", line 95, in <module>
main()
File "/Users/salayhin/google-cloud-sdk/lib/gcloud.py", line 54, in main
from googlecloudsdk.core.util import encoding
File "/Users/salayhin/google-cloud-sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
from googlecloudsdk.core.util import lazy_regex
File "/Users/salayhin/google-cloud-sdk/lib/googlecloudsdk/core/util/lazy_regex.py", line 25, in <module>
from googlecloudsdk.core.util import lazy_regex_patterns
ImportError: cannot import name lazy_regex_patterns
It seems like it's just an error from the Google Cloud SDK happening here indicating that you are probably missing this file on the same directory.
I would recommend re-install the Google Cloud SDK on whatever system you are using.

outlook mailbox SMTPDataError 550 delivery result banner

I was using smtp service of outlook mailbox in my web app. And it worked well in last several days. However a sudden error occured during a usual test:
File "/usr/lib/python3.4/smtplib.py", line 799, in sendmail
raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (550, b'5.3.4 554-554 5.2.0 STOREDRV.Deliver;delivery result banner')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
self.run()
File "/usr/lib/python3.4/threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
File "/home/lancecopper/code/python/flasky/app/email.py", line 9, in send_async_email
mail.send(msg)
File "/home/lancecopper/code/flasky/venv/lib/python3.4/site-packages/flask_mail.py", line 492, in send
message.send(connection)
File "/home/lancecopper/code/flasky/venv/lib/python3.4/site-packages/flask_mail.py", line 152, in __exit__
self.host.quit()
File "/usr/lib/python3.4/smtplib.py", line 867, in quit
res = self.docmd("quit")
File "/usr/lib/python3.4/smtplib.py", line 403, in docmd
self.putcmd(cmd, args)
File "/usr/lib/python3.4/smtplib.py", line 349, in putcmd
self.send(str)
File "/usr/lib/python3.4/smtplib.py", line 341, in send
raise SMTPServerDisconnected('please run connect() first')
smtplib.SMTPServerDisconnected: please run connect() first
I have little knowledge about underlining mechanism of smtp. Can anybody give me some clue about this kind of error.
By the way, I'm a poor guy living inside GFW(Great Firewall of China).Would it be possible that the error above was caused by interruption of GFW?
I encountered this issues when using mutt to.
login your account and verify mobile phone number and check it again.
You may got message like on your phone:
[TLSG] Microsoft 访问代码:2130