Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting invalid function name warning using Python

Tags:

python

pylint

I am formatting Python code using pylint and getting some unwanted warning messages which are given below.

C:204, 0: Invalid function name "sendPasswordViaEmail" (invalid-name)
C:207, 4: Invalid variable name "to" (invalid-name)
W:213, 4: Statement seems to have no effect (pointless-statement)

I am providing my code related to the above messages below.

if request.method == 'POST':
        name = request.POST.get('uname')
        email = request.POST.get('uemail')
        range_start = 10 ** (4 - 1)
        range_end = (10 ** 4) - 1
        password = randint(range_start, range_end)
        passw = User(
            uname=name,
            password=password,
            raw_password=password,
        )
        passw.save()
        sendPasswordViaEmail(str(password), email)
    return render(request, 'bookingservice/login.html')


def sendPasswordViaEmail(password, email):
    """ Send email to user"""

    to = email
    gmail_user = settings.EMAIL
    gmail_pwd = settings.PASSWORD
    smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(gmail_user, gmail_pwd)
    header = 'To:' + to + '\n' + 'From: ' + \
        gmail_user + '\n' + 'Subject:password \n'
    msg = header + '\n Your password is\n\n' + password
    smtpserver.sendmail(gmail_user, to, msg)
    smtpserver.close()
like image 413
satya Avatar asked Aug 08 '17 05:08

satya


1 Answers

These messages are warnings (your code works), not errors.

sendPasswordViaEmail is a camel case name. Functions should be "snake case". Rename it send_password_via_email.

to is too short. Try recipient or something else meaningful in place.

The line containing smtpserver.ehlo whithout parentheses does nothing and is thus useless.

like image 61
glenfant Avatar answered Nov 15 '22 04:11

glenfant