Please make sure you install the correct Python driver from here. Here you can find a great Python tutorial to connect to Azure SQL. Here you will also find how to create an Azure Automation Runbook with Python.
You can try the following Python code to connect from your computer to Azure SQL:
import pyodbc
server = 'sqlservertest.database.windows.net'
database = 'Mydatabase'
username ='ServerAdmin'
password = '****'
driver= '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+
';SERVER='+server+
';PORT=1433;DATABASE='+database+
';UID='+username+
';PWD='+ password)
cursor = cnxn.cursor()
cursor.execute("SELECT * FROM TableInYourDatabase")
row = cursor.fetchone()
while row:
print (str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
In addition, please make sure you have created a SQL login with permission to connect to the database. You can try creating a contained database user as shown below and used that contained login to connect to the database.
CREATE USER yourlogin WITH PASSWORD = 'Yh-EhGFjh+';
GO
exec sp_addRoleMember 'db_datareader', 'yourlogin';
GO
Make sure you have created a firewall rule as explained on this documentation and the server name and database names are correct.
Another option you have to schedule execution of Python code is using Azure Data Factory along with Azure Batch as explained here.