receiver_email = open(subscribers.txt, 'r').readlines()
for i in receiver_email:
current_mail = i.removesuffix("\n")
print(type(current_mail))
print(type(smtp_data[2]))
print(type(message))
smtp.sendmail(smtp_data[2], current_mail, message.as_string())
this previous code throws out an attribute error 'list' object has no attribute 'encode' on last line
the print statements yield out the following:
<class 'str'>
<class 'str'>
<class 'email.mime.multipart.MIMEMultipart'>
Any ideas on why this isn't working?
edit:
here is an example of the contents of the txt file
myemail1#outlook.com
myemail2#hotmail.com
myemail3#gmail.com
fulltraceback:
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 269, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\Administrator\Desktop\smtp.py", line 62, in <module>
smtp.sendmail(smtp_data[2], current_mail, message.as_string())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\email\message.py", line 158, in as_string
g.flatten(self, unixfrom=unixfrom)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\email\generator.py", line 116, in flatten
self._write(msg)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\email\generator.py", line 199, in _write
self._write_headers(msg)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\email\generator.py", line 226, in _write_headers
self.write(self.policy.fold(h, v))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\email\_policybase.py", line 326, in fold
return self._fold(name, value, sanitize=True)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\email\_policybase.py", line 369, in _fold
parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
AttributeError: 'list' object has no attribute 'encode'
See below code - you can write it as UTF-8 in current_mail.encode('utf-8')
It turned out that the message.as_string messes up when I am using a list of emails for some reason, I changed it from attaching the email context to a mimetext to directly setting it to mimetext and it seemed to do the trick.
Huge thanks to Barmar
Related
I try to use some libraries including "https://api.coinbase.com/v2/prices/spot?currency=USD"
but i got this error:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\Hessam\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Hessam\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\Hessam\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 268, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 242, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "c:\Users\Hessam\Python code\requests.py", line 3
r = requests.get(https://jsonplaceholder.typicode.com/posts)
^
SyntaxError: invalid syntax
so please guide me on this
thanks in advance
This is my first question here,
I mainly use VSCode as IDE, and often play Python codes, and I stuck here,
'''
#!/usr/bin/env python
import os,sys
print(os.getcwd())
print('__file__:', __file__)
fileP = str(__file__).replace("c:\\", "")
print(fileP)
*print(os.chdir("C:\\Users\\playf\\AppData\\Local\\Programs\\Python\\Python38\\Lib\\site-packages\\tespy"))*
'''
Trackback is like below
'''
File "C:\Users\playf\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\playf\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\playf\.vscode\extensions\ms-python.python-2020.8.103604\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\playf\.vscode\extensions\ms-python.python-2020.8.103604\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\playf\.vscode\extensions\ms-python.python-2020.8.103604\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Users\playf\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 263, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\playf\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\playf\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\playf\AppData\Local\Programs\Python\Python38\Lib\site-packages\line4py\setup.py", line 11, in <module>
os.chdir()
**TypeError: chdir() missing required argument 'path' (pos 1)**
'''
I tried another typing of pass like
'''
"C:\\Users\\playf\\AppData\\Local\\Programs\\Python\\Python38\\Lib\\site-packages\\tespy"
"Users\\playf\\AppData\\Local\\Programs\\Python\\Python38\\Lib\\site-packages\\tespy"
"/Users/playf/AppData/Local/Programs/Python/Python38/Lib/site-packages/tespy"
"Users/playf/AppData/Local/Programs/Python/Python38/Lib/site-packages/tespy"
'''
all is out,
is this problem about escape sequence or what?
Why Win10 for programming?
You can install Ubuntu in 15 minutes and code fast and easily
Previously translating the name with a non-bmp map prevented emojis in names from crashing the script, but suddenly it doesn't work and i don't know why.
I tried adding a try/except block to see what the problem is, but the except doesn't catch the exception at all. I used the debugger and the code just jumps to the line after the except block (!?)
Here is the problematic code:
The line
logger.info(f"Liking tweet from user {name}")
throws the following exception:
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\JGC\anaconda3\lib\logging\__init__.py", line 1028, in emit
stream.write(msg + self.terminator)
File "C:\Users\JGC\anaconda3\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufffd' in position 40: character maps to <undefined>
Call stack:
File "C:\Users\JGC\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\JGC\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\JGC\.vscode\extensions\ms-python.python-2020.6.91350\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\JGC\.vscode\extensions\ms-python.python-2020.6.91350\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\JGC\.vscode\extensions\ms-python.python-2020.6.91350\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Users\JGC\anaconda3\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\JGC\anaconda3\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\JGC\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\JGC\Desktop\Python\Templates de bots\Twitter Template\posting-bot\machado.py", line 169, in <module>
stream.filter(track=HASHTAGS, languages=["pt"])
File "C:\Users\JGC\anaconda3\lib\site-packages\tweepy\streaming.py", line 474, in filter
self._start(is_async)
File "C:\Users\JGC\anaconda3\lib\site-packages\tweepy\streaming.py", line 389, in _start
self._run()
File "C:\Users\JGC\anaconda3\lib\site-packages\tweepy\streaming.py", line 289, in _run
self._read_loop(resp)
File "C:\Users\JGC\anaconda3\lib\site-packages\tweepy\streaming.py", line 351, in _read_loop
self._data(next_status_obj)
File "C:\Users\JGC\anaconda3\lib\site-packages\tweepy\streaming.py", line 323, in _data
if self.listener.on_data(data) is False:
File "C:\Users\JGC\anaconda3\lib\site-packages\tweepy\streaming.py", line 54, in on_data
if self.on_status(status) is False:
File "c:\Users\JGC\Desktop\Python\Templates de bots\Twitter Template\posting-bot\machado.py", line 59, in on_status
logger.info(f"Liking tweet from user {name}")
Message: 'Liking tweet from user maya | �; aridante'
Arguments: ()
I want alembic to get the current stored procedure from DB compare it to the one in the code. If they are different to update the DB.
I edited the env.py file to check for this, and generate an upgrade versions of the raw SQL.
when running the following :
writer = rewriter.Rewriter()
#writer.rewrites(ops)
def stored_procedure(context, revision, op):
if not change_detected():
print("did not detect difference in stored procedure.")
return op
else:
print("detected difference in stored")
package_sql = open(migration_file_path, "r")
package_sql = migration_file.read()
package_sql = '"""' + package_sql + '"""'
return [
op,
op.get_bind().execute(package_sql),
]
Traceback (most recent call last):
File "c:\Project\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Project\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 432, in main
run()
File "c:\Project\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Project\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Project\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Project\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:/Project/manage.py", line 15, in <module>
manager.run()
...
File "C:\Project\ENV\lib\site-packages\alembic\runtime\migration.py", line 351, in run_migrations
for step in self._migrations_fn(heads, self):
File "C:\Project\ENV\lib\site-packages\alembic\command.py", line 173, in retrieve_migrations
revision_context.run_autogenerate(rev, context)
File "C:\Project\ENV\lib\site-packages\alembic\autogenerate\api.py", line 433, in run_autogenerate
self._run_environment(rev, migration_context, True)
File "C:\Project\ENV\lib\site-packages\alembic\autogenerate\api.py", line 483, in _run_environment
hook(migration_context, rev, self.generated_revisions)
File "migrations\env.py", line 167, in process_revision_directives
stored_procedure(context, revision, directives)
File "migrations\env.py", line 146, in stored_procedure
op.get_bind().execute(package_sql),
AttributeError: 'list' object has no attribute 'get_bind'
I'm using Python 2.7 with SQLAlchemy.
I'm trying to see if I can use Dogpile.Cache.
I've installed dogpile cache using
pip install dogpile.cache
but when I try to run the example given by SQLAlchemy (helloworld.py)
I keep getting ImportError: No module named fcntl. I thought the newest Dogpile.Cache resolved the windows issue...
Could someone please help?
Thank you.
UPDATE
Ok, the example is creating the database and cache. But when it is trying to load data using FromCache it is giving me an error.
people = Session.query(Person).options(FromCache("default")).all()
Here is the Traceback
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\JKIM\Downloads\DogpileCacheTest\examples\dogpile_caching\helloworld.py", line 13, in <module>
people = Session.query(Person).options(FromCache("default")).all()
File "build\bdist.win-amd64\egg\sqlalchemy\orm\query.py", line 2613, in all
File "examples\caching_query.py", line 63, in __iter__
return self.get_value(createfunc=lambda: list(Query.__iter__(self)))
File "examples\caching_query.py", line 108, in get_value
expiration_time=expiration_time
File "C:\Python27\lib\site-packages\dogpile\cache\region.py", line 657, in get_or_create
async_creator) as value:
File "C:\Python27\lib\site-packages\dogpile\lock.py", line 154, in __enter__
return self._enter()
File "C:\Python27\lib\site-packages\dogpile\lock.py", line 87, in _enter
value = value_fn()
File "C:\Python27\lib\site-packages\dogpile\cache\region.py", line 610, in get_value
value = self.backend.get(key)
File "C:\Python27\lib\site-packages\dogpile\cache\backends\file.py", line 220, in get
with self._dbm_file(False) as dbm:
File "C:\Python27\lib\contextlib.py", line 17, in __enter__
return self.gen.next()
File "C:\Python27\lib\site-packages\dogpile\cache\backends\file.py", line 212, in _dbm_file
with self._use_rw_lock(write):
File "C:\Python27\lib\contextlib.py", line 17, in __enter__
return self.gen.next()
File "C:\Python27\lib\site-packages\dogpile\cache\backends\file.py", line 207, in _use_rw_lock
with self._rw_lock.read():
File "C:\Python27\lib\contextlib.py", line 17, in __enter__
return self.gen.next()
File "C:\Python27\lib\site-packages\dogpile\cache\backends\file.py", line 327, in read
self.acquire_read_lock(True)
File "C:\Python27\lib\site-packages\dogpile\cache\backends\file.py", line 408, in acquire_read_lock
return self._acquire(wait, os.O_RDONLY, self._module.LOCK_SH)
File "C:\Python27\lib\site-packages\dogpile\util\langhelpers.py", line 63, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "C:\Python27\lib\site-packages\dogpile\cache\backends\file.py", line 400, in _module
import fcntl
ImportError: No module named fcntl