pySerial- need help.

K

kamarudin samsudin

Hi all,

I try to invoke python serial script via my browser using PHP (exec
function). For the serial communication, i used pySerial module. It
fine when it run it as root but when i try to run it from browser, i
got this error in my httpd/error_log

File "weather1.py", line 9, in ?
ser=serial.Serial('/dev/ttyS0',9600,timeout=1)
File "/usr/lib/python2.3/site-packages/serial/serialutil.py", line
153, in __init__
self.open()
File "/usr/lib/python2.3/site-packages/serial/serialposix.py", line
137, in open
raise SerialException("Could not open port: %s" % msg)
serial.serialutil.SerialException: Could not open port: [Errno 13]
Permission denied: '/dev/ttyS0'

i tried chmod go+wr /dev/ttyS0 but i still got the error.

BTW, i used apache 2.0.52, PHP 4.3.10 and Fedora Core 3

Thanks in advance.
 
J

Joal Heagney

kamarudin said:
Hi all,

I try to invoke python serial script via my browser using PHP (exec
function). For the serial communication, i used pySerial module. It
fine when it run it as root but when i try to run it from browser, i
got this error in my httpd/error_log

File "weather1.py", line 9, in ?
ser=serial.Serial('/dev/ttyS0',9600,timeout=1)
File "/usr/lib/python2.3/site-packages/serial/serialutil.py", line
153, in __init__
self.open()
File "/usr/lib/python2.3/site-packages/serial/serialposix.py", line
137, in open
raise SerialException("Could not open port: %s" % msg)
serial.serialutil.SerialException: Could not open port: [Errno 13]
Permission denied: '/dev/ttyS0'

i tried chmod go+wr /dev/ttyS0 but i still got the error.

BTW, i used apache 2.0.52, PHP 4.3.10 and Fedora Core 3

Thanks in advance.
This sounds more like a linux problem rather than a python problem.
Modern linux'es set the permissions in /etc/security files, and these
will override any chmod that you do in the /dev/ directory. What you
need to do is edit /etc/security/console.perms file.

In Mandrake I have the following lines:

------------------------------------------------
<serial>=/dev/ttyS* /dev/rfcomm* /dev/ircomm*
---and lower down ---
<console> 0660 <serial> 0660 root.uucp
------------------------------------------------
You can change the <console> / <serial> line so that you have 666
permissions, but it would probably be better to ensure that the serial
is assigned a non-root group (uucp in my case), change the group of your
script to match, set the sgid bit on your program and change the execute
permissions on your script so everyone can use it.

chmod 2755 <script>

This way your script will execute as group uucp, and theoretically it
should have permission to access the /dev/ttyS* devices.

Hope that helps,

Joal
 
J

Joal Heagney

Joal said:
kamarudin said:
Hi all,

I try to invoke python serial script via my browser using PHP (exec
function). For the serial communication, i used pySerial module. It
fine when it run it as root but when i try to run it from browser, i
got this error in my httpd/error_log

File "weather1.py", line 9, in ?
ser=serial.Serial('/dev/ttyS0',9600,timeout=1)
File "/usr/lib/python2.3/site-packages/serial/serialutil.py", line
153, in __init__
self.open()
File "/usr/lib/python2.3/site-packages/serial/serialposix.py", line
137, in open
raise SerialException("Could not open port: %s" % msg)
serial.serialutil.SerialException: Could not open port: [Errno 13]
Permission denied: '/dev/ttyS0'

i tried chmod go+wr /dev/ttyS0 but i still got the error.

BTW, i used apache 2.0.52, PHP 4.3.10 and Fedora Core 3
Thanks in advance.
This sounds more like a linux problem rather than a python problem.
Modern linux'es set the permissions in /etc/security files, and these
will override any chmod that you do in the /dev/ directory. What you
need to do is edit /etc/security/console.perms file.

In Mandrake I have the following lines:

------------------------------------------------
<serial>=/dev/ttyS* /dev/rfcomm* /dev/ircomm*
---and lower down ---
<console> 0660 <serial> 0660 root.uucp
------------------------------------------------
You can change the <console> / <serial> line so that you have 666
permissions, but it would probably be better to ensure that the serial
is assigned a non-root group (uucp in my case), change the group of your
script to match, set the sgid bit on your program and change the execute
permissions on your script so everyone can use it.

*sigh*

su to root first.
chown root.uucp <script>

(Assuming you're going to install this as a root binary.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top