Does someone get this error packing py project with twilio?
"No module named 'twilio' [19300] Failed to execute script 'pcONpcesc' due to unhandled exception!"
If i execute de py script with sublimetext "for example" it works fine.
Sends email, whatsapp and mqtt without any issue.
I tried already with venv and also without virtual environment. Tried Pyinstaller and auto-py-to-exe. The same error.
Tried: "pyinstaller --onefile --hidden-import twilio.rest pcONpcesc.py"
Why is twilio not included?
Finally i find the twilio library on requirements.txt.
Code:
import smtplib
from email.message import EmailMessage
import random
from paho.mqtt import client as mqtt_client
from twilio.rest import Client
from datetime import datetime, timedelta
from datetime import date
from pytz import timezone
data_e_hora_atuais = datetime.now()
fuso_horario = timezone("Portugal")
data_e_hora_portugal = data_e_hora_atuais.astimezone(fuso_horario)
data_e_hora_portugal_em_texto = data_e_hora_portugal.strftime("%d/%m/%Y %H:%M:%S")
global str_data
str_data = data_e_hora_portugal_em_texto
assunto = "PC - INFO"
mensagem = f"PC ESCR [DSK-FDESK] acabou de ser ligado. {str_data}"
para = "[email protected]"
def email_alerta(subject, body, to):
msg = EmailMessage()
msg.set_content(body)
msg["subject"] = subject
msg["to"] = to
user = "[email protected]"
password = "1234567887654321"
msg["from"] = user
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(user, password)
server.send_message(msg)
server.quit()
email_alerta(assunto, mensagem, para)
broker = "broker.emqx.io"
port = 8083
topic = "GERAL/TESTE1"
client_id = f"python-mqtt-{random.randint(0, 1000)}"
username = "userabc"
password = "pass1234"
msg1 = mensagem
def enviamqtt():
def connect_mqtt():
def on_connect(client_id, userdata, flags, rc):
if rc == 0:
print("Connectado ao MQTT Broker!")
else:
print("Falha na conexão, retornou o codigo %d\n", rc)
client = mqtt_client.Client(client_id)
client.subscribe(topic)
client.username_pw_set(username, password)
client.on_connect = on_connect
client.connect(broker, port)
return client
connect_mqtt()
def publish1(client):
result = client.publish(topic, msg1)
result: [0, 1]
status = result[0]
if status == 0:
print(f"Enviado {msg1} para o topico {topic}")
else:
print(f"Falha ao enviar mensagem para o topico {topic}")
client = connect_mqtt()
publish1(client)
enviamqtt()
account_sid = "accountid"
auth_token = "tokengenerated"
client = Client(account_sid, auth_token)
message = client.messages.create(from_="whatsapp:+141999900000", body=mensagem, to="whatsapp:+mynumber")
print(message.sid)