Why am I reviving AttributeError: 'int' object has no attribute 'find'? - python

import smtplib
smtpserver = s.connect("mail.btinternet.com", 465)
SMTP.helo("mail.btinternet.com")
SMTP.ehlo("mail.btinternet.com")
file = open("Combo.txt", "r")
for line in file:
x = line.split(":")
user = x[0]
password = x[1]
s.login(user, password)
print("[+] Password Found: %s" % password)
if smtplib.SMTPAuthenticationError:
print("Incorrect")
Here's my code. It checks a list of email/password combinations from a file to see if it is on a specific server (in my case BT).
But I am having trouble with the library names, I am not sure what to use. I checked on python docs but it wasn't clear enough, if someone can tell me as to what is incorrect I would deeply appreciate it.
Error received.
This will also give me errors for the other incorrect library names
Traceback (most recent call last):
File "main.py", line 3, in <module>
smtpserver = s.connect("mail.btinternet.com", 465)
NameError: name 's' is not defined
exited with non-zero status

For your problem I think the reason why as to your libraries are not working properly is because you're calling your imported library inconsistently:
e.g. sometimes you type 's.xxxxx', sometimes you type 'SMTPlib.xxxxx' for your module attributes, you should import smtplib as 's'.
So what does this is it stores the library in a short form named 's', so whenever you call a module or use a function from the library, you don't have to type the full '.smtplib' but instead just type a '.s' extension behind the specific function:
import smtplib as s
smtpserver = s.connect("mail.btinternet.com", 465)
s.helo("mail.btinternet.com")
s.ehlo("mail.btinternet.com")
file = open("Combo.txt", "r")
for line in file:
x = line.split(":")
user = x[0]
password = x[1]
s.login(user, password)
print("[+] Password Found: %s" % password)
if s.SMTPAuthenticationError:
print("Incorrect")
Should fix your problems now. remember to call functions from the specific library name in a consistent manner ('s').

Related

Python: Type Error, but I don't know what to change! Question for Someone who know many about Smtplib

I wanted to do an Email writer. I saw a tutorial and this came out:
import smtplib
import os
user = os.getenv("SMTP_USER")
pwd = os.getenv("SMTP_PWO")
mail_text = "Hallo, \n\ndas ist ein Test!\n\n"
subject = "Python Mail"
MAIL_FROM = "x.muelfellner#outlook.de"
RCPT_TO = input("Empfänger: ")
DATA = "From:%s\nTo:%s\nSubject:%s\n\n%" \
(MAIL_FROM,RCPT_TO,subject,mail_text)
server = smtplib.SMTP("secure.emailsrvr.com:587")
server.starttls()
server.login(user,pwd)
server.sendmail(MAIL_FROM,RCPT_TO,DATA)
server.quit()
But when I'm running the code there's an Error. Here:
Traceback (most recent call last):
File "/home/pi/Bookshelf/Pyton/SendEmail.py", line 12, in <module>
(MAIL_FROM,RCPT_TO,subject,mail_text)
TypeError: 'str' object is not callable
I don't know what i have to change! Can someone help me?
Your problem isn't related to smtplib; it's just a syntax error.
You're inadvertently trying to call a string (I removed the \ continuation):
DATA = "From:%s\nTo:%s\nSubject:%s\n\n%"(MAIL_FROM,RCPT_TO,subject,mail_text)
It should be
DATA = "From:%s\nTo:%s\nSubject:%s\n\n%s" % (MAIL_FROM,RCPT_TO,subject,mail_text)
to format a string.

How to fix a TypeError saying 'module' object is not callable

My wave.py file:
import User_Account
username = input('Username: ')
password = input('Password: ')
Session = User_Account(username, password)
My User_Account.py file:
import tidalapi
class User_Account:
def __init__(self, username_, password_):
self.username = username_
self.password = password_
def login(self):
session = tidalapi.Session()
return session.login(self.username, self.password)
When I run the above code in PyCharm I get the following error.
TypeError: 'module' object is not callable
I am reading examples of OOP in Python - such as this - and even when I run their code, I get the same error. I've searched for it here and on Google but the solutions don't seem to fix the issue.
Any suggestions as to what I'm doing wrong?
Thank you for your time and if there is anything I can supply to improve my question, please don't hesitate.
EDIT: Full traceback
Traceback (most recent call last):
File "/home/doug/PycharmProjects/Wave/wave.py", line 6, in <module>
Session = User_Account(username, password)
TypeError: 'module' object is not callable
I believe the problem is that you are bringing in the module but not specifying the class you want from that module.
I think the following change to your wave.py would fix this...
Session = User_Account.User_Account(username, password)
Even better, rather than importing User_Account, you might want to say...
from User_Account import User_Account
If you do this, your "Session =" call will work as you currently have it.
It's exactly like the error says, a module is not callable. It looks like you meant to run from user_account import User_Account instead of import User_Account.
Note that import User_Account would fail on a case-sensitive platform like Linux. If you did actually want to import user_account.py you would write import user_account.

Getting error while encrypting the password using salt in Python

I am getting error while encrypting the password using Python. I am explaining the error below.
Error:
Traceback (most recent call last):
File "password.py", line 60, in <module>
hashed_password = hashlib.sha512(sword + salt).hexdigest()
TypeError: cannot concatenate 'str' and 'list' objects
My code is given below.
import hashlib
value = "2Y7xk5vrs5DeCcSdinRVKQ=="
salt = value.split()
sword = "subhra1234"
hashed_password = hashlib.sha512(sword + salt).hexdigest()
print(hashed_password)
Here I need to use own salt value and trying to encrypting the password. Please help to resolve this error.
Like #MosesKoledoye said, you don't need to call split on the salt:
import hashlib
salt = "2Y7xk5vrs5DeCcSdinRVKQ=="
sword = "subhra1234"
hashed_password = hashlib.sha512(sword + salt).hexdigest()
print(hashed_password)

Python email bot Pyzmail/IMAPclient error

So I'm working on a Python script to extract text from an email and following these instructions to do so. This is the script thus far:
import imapclient
import pprint
import pyzmail
mymail = "my#email.com"
password = input("Password: ")
imapObj = imapclient.IMAPClient('imap.gmail.com' , ssl=True)
imapObj.login(mymail , password)
imapObj.select_folder('INBOX', readonly=False)
UIDs = imapObj.search(['SUBJECT Testing'])
rawMessages = imapObj.fetch([5484], ['BODY[]'])
message = pyzmail.PyzMessage.factory(rawMessages[5484]['BODY[]'])
However I'm getting this error:
message = pyzmail.PyzMessage.factory(rawMessages[5484]['BODY[]'])
KeyError: 5484
5484 being the ID for the email that the search function finds. I've also tried putting UIDs in instead of 5484, but that doesn't work either. Thanks in advance!
Thank you #Madalin Stroe .
I use python3.6.2 and pyzmail1.0.3 on Win10.
When I run
message = pyzmail.PyzMessage.factory(rawMessages[4]['BODY[]'])
The ERR shows like this:
Traceback (most recent call last):
File "PATH/TO/mySinaEmail.py", line 42, in <module>
message = pyzmail.PyzMessage.factory(rawMessages[4]['BODY[]'])
KeyError: 'BODY[]'
When I modified this to message = pyzmail.PyzMessage.factory(rawMessages[4][b'BODY[]']), it run well.
Try replacing ['BODY[]'] with [b'BODY[]']

Shelve module in python not working: "db type cannot be determined"

I am trying to make a simple password-storing program in Python, and it seems pretty simple so I am wondering if I am using shelve wrong.
I have the main .py file:
import shelve
passwords = shelve.open('./passwords_dict.py')
choice = raw_input("Add password (a) or choose site (c)?")
if choice[0] == 'a':
site_key = raw_input("Add for which site? ").lower()
userpass = raw_input("Add any info such as username, email, or passwords: ")
passwords[site_key] = userpass
else:
site = raw_input("Which site? ").lower()
if site in passwords:
print "Info for " + site + ": " + passwords[site]
else:
print site, "doesn't seem to exist!"
print "Done!"
passwords.close()
And the other file, passwords_dict.py, is just an empty dictionary.
But when I try to run the program, I get this error:
Traceback (most recent call last):
File "passwords.py", line 3, in <module>
passwords = shelve.open('passwords_dict.py')
File "/usr/lib/python2.7/shelve.py", line 239, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/usr/lib/python2.7/shelve.py", line 223, in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback)
File "/usr/lib/python2.7/anydbm.py", line 82, in open
raise error, "db type could not be determined"
anydbm.error: db type could not be determined
When I try to use anydbm instead, I get this error:
Traceback (most recent call last):
File "passwords.py", line 3, in <module>
passwords = anydbm.open('passwords_dict.py')
File "/usr/lib/python2.7/anydbm.py", line 82, in open
raise error, "db type could not be determined"
anydbm.error: db type could not be determined
And when I try to use dbm instead, I get this error:
Traceback (most recent call last):
File "passwords.py", line 3, in <module>
passwords = dbm.open('./passwords_dict.py')
dbm.error: (2, 'No such file or directory')
What am I doing wrong? Is there another way to store a dictionary and still be able to extract keys using user input (rather than the entire dictionary, which I suppose is what pickle does)?
I think you're misunderstanding how the shelve module works. It opens a database file. When you try and open an existing file that contains a Python script, it's trying to detect what database type the file contains (since shelve supports multiple backend databases).
I think instead you want something like this:
import os
import shelve
curdir = os.path.dirname(__file__)
passwords = shelve.open(os.path.join(curdir, 'password_db'))
This will create a new file in the same directory as your script called password_db.<db> where <db> is an implementation-specific database file extension.
I've experienced this issue as well. It seems to be related to undocumented conditions for the filename argument of shelve.open. It is currently very intransparent (e.g. shelve.open("/tmp/tmphTTQLda") works while shelve.open("/tmp/tmphTTQLd") doesn't). Failure and success of variable filenames are hard to predict. I requested an explanation in form a documentation enhancement at http://bugs.python.org/issue23174.
In my case opening a persistent dict outside shelve and passing it to shelve.Shelve works, e.g. code
a = dumbdbm.open(tempfile.mkstemp()[1])
b = shelve.Shelf(dict=a)
and do with b what you'd have done with the return value of shelve.open.
There is one bug with anydb https://bugs.python.org/issue13007 that could not use the right identification for gdbm files.
So if you are trying to open a valid gdbm file with shelve and is thorwing that error use this instead:
mod = __import__("gdbm")
file = shelve.Shelf(mod.open(filename, flag))
More information on this question: shelve db type could not be determined, whichdb is not recognizing gdb

Categories