BlaiseP
Posts: 8
Joined: Tue Feb 10, 2015 9:11 pm

SMTP email Errno 13 Permission denied

Mon Sep 07, 2015 4:11 pm

I copied this SMTP/ email.py program out of the Python manual into the Geany IDE;

Code: Select all

#!/usr/bin/env python
import smtplib

sender    = '[email protected]'
receivers = '[email protected]'
message   = ("""
Raspi e-mail test
-- 
Pi
""")
try:
	smtpObj = smtplib.SMTP('smtp.gmail.com',25)
	smtpObj.sendmail(sender,receivers,message)
	print "email sent."
except SMTPException:
	print "Error: email not sent."
If I hit compile, I get 12 red lines in the compiler window, of which the last 3 lines are:
...
with open(cfile,'wb') as fc:
IOError: [Errno 13] Permission denied: 'email.pyc'

Compilation failed.

What is wrong here?

RobHenry
Posts: 452
Joined: Fri Sep 21, 2012 9:04 pm
Location: UK

Re: SMTP email Errno 13 Permission denied

Mon Sep 07, 2015 6:05 pm

It's getting a permissions error when creating the interpreted byte code email.pyc - do you have permission to create a file in the directory you're using?

BlaiseP
Posts: 8
Joined: Tue Feb 10, 2015 9:11 pm

Re: SMTP email Errno 13 Permission denied

Mon Sep 07, 2015 8:00 pm

The email.py script is in home/pi/www ( ~/www/email.py ), yes I can create a file there, without using sudo.

The 4 last error lines are ;
...
File "/usr/lib/pyton2.7/py_compile.py", line 123, in compile
with open(cfile,'wb') as fc:
IOError: [Errno 13] Permission denied: 'email.pyc'

Compilation failed.
and in that directory /usr/lib/pyton2.7 I can only open and save a file with sudo, e.g.
/usr/lib/pyton2.7 $ nano tmp.txt
opens a file but I cannot save it
/usr/lib/pyton2.7 $ sudo nano tmp.txt
opens a file and I can save it.

BlaiseP
Posts: 8
Joined: Tue Feb 10, 2015 9:11 pm

Re: SMTP email Errno 13 Permission denied

Mon Sep 07, 2015 8:24 pm

BlaiseP wrote:The email.py script is in home/pi/www ( ~/www/email.py )
There already was a file ~/www/email.pyc, I deleted it and compiled again, now I did not get any compile errors ('Compilation finished successfully.') :) but if I run the program I now get
File "/var/www/email.py", Line 15, in <module>
except SMTPException:
NameError: name 'SMTPException' is not defined
in the LXterminal window. :(

Return to “Python”