Why _thread doesnt work on the remote server?

17 views
Skip to first unread message

Sergei Sokov

unread,
Feb 26, 2021, 1:09:05 PM2/26/21
to Django users

This code works on my local server, but doesnt work on the hosting. What could be the problem?

import _thread

def email_index(*args):
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login('k...@gmail.com', 'pas')
    try:
        server.sendmail('k...@gmail.com', 's...@gmail.com', body_mes.encode('utf-8')) print('ok')
     except:
         print('An error occurred when trying to send an email')
try:
    _thread.start_new_thread( email_index, ("Thread-1", 2, ) )
except:
    print ("Error: unable to start thread")

Kasper Laudrup

unread,
Feb 26, 2021, 1:21:39 PM2/26/21
to django...@googlegroups.com
On 26/02/2021 19.09, Sergei Sokov wrote:
> This code works on my local server, but doesnt work on the hosting. What
> could be the problem?
>

Hard to tell. You're explicitly throwing away any relevant information
by using a catch-all exception handler.

Do any of your "an error happened" messages reach a log anywhere?

No matter what, don't catch exceptions if you don't have any way to
handle them anyway, that makes it possible to debug and fix errors like
these.

Kind regards,

Kasper Laudrup
Reply all
Reply to author
Forward
0 new messages