When I develop a Python application, sometimes I need to access my Gmail account from the Python source code. But this is not allowed by google by default, you need to configure some settings to make it happen. This article will tell you how to make your Gmail account accessed by less secure apps such as from Python source code.
1. Turn On Allow Less Secure Apps Access Google Account Steps.
- Go to https://accounts.google.com/ web page to login to your google account.
- Click the Security menu item on left, then scroll down on right and click the Turn on access(not recommended) link under the Less secure app access section in right.
- Now turn on Allow less secure apps:ON toggle button on the new page.
- Now click the back arrow in the title, you can find the Allow less secure apps has been turned on. You can access your Gmail account in your Python code now.
- But as google said this action is not recommended, because there will be risks for your Gmail account. So you had better turn it off after your testing to make your google account more safety.
- If you can not find the Less secure app access section on the Security page right side, this is because your Gmail account has enabled the 2-step verification.
- To fix this error, you can either disable the 2-step verification or you can create an app special password for your application, then your less secure apps can access the Gmail account.
- First login to your Google account, then click the Security link on the page left side.
- Then on the page right side
Signing in to Googlesection, click the
- It will open the
App passwordspage. Select
- You can also select
Other (Custom name)from the drop-down list to create your own app password.
- Click the Generate button to create the app password.
- Now it will popup a Generated app password dialog to let you see the app password and how to use it in your device and application.