Forums

[Errno 2] No such file or directory: 'letter_templates'

import pandas, random, smtplib, datetime, os

connection = smtplib.SMTP('smtp.gmail.com', 587) connection.starttls() connection.login(user=USER_NAME, password=PASSWORD) files = os.listdir('letter_templates')

today = datetime.datetime.now() data = pandas.read_csv('birthdays.csv')

for row in range(0, len(data)): if data.iloc[row]['month'] == today.month and data.iloc[row]['day']: with open(f'/home/kumaran101088/birthday_wish/letter_templates/{random.choice(files)}') as body_file: content = body_file.read().replace('[NAME]', data.iloc[row]['name']).replace('Kumaran', 'Angela') connection.sendmail(from_addr=USER_NAME, to_addrs=data.iloc[row]['email'], msg=f'Subject: Happy Birthday!\n\n{content}')

connection.close()

See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

Hey Glenn, thank you for the response but, I did mention the absolute path correctly as you can see in the code, it still doesn't work.

It works on the bash console when I run it but, it doesn't work when I schedule as a task.

How does your code look like now?

f'/home/kumaran101088/birthday_wish/letter_templates/{random.choice(files)}'

-----This is how it looks like at the moment. It works in the Bash Console but, as a task i get [Errno 2] No such file or directory: 'letter_templates'

-----The directory definitely exits and the spelling is correct since it works via Bash Console.

If the error is exactly

[Errno 2] No such file or directory: 'letter_templates'

...then it must be running an older version of your code from somewhere -- if if was the new code then it would say

[Errno 2] No such file or directory: '/home/kumaran101088/birthday_wish/letter_templates/'

I checked that too. Opened code in the editor and confirmed it is the latest one. I even deleted and created multiple tasks from scratch still the same.

You know what, it worked!

I deleted birthday_wish folder and moved all the contents under the main project kumaran101088. Updated the code to f'/home/kumaran101088/letter_templates/{random.choice(files)}'

But, why is it not accepting a folder within a folder? is it because i am using a free account?

Free accounts don't have any filesystem restrictions (apart from the limit on the total amount of data that you can store). Can we take a look at your code? We can see it from our admin interface, but we always ask for permission first.