By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,713 Members | 764 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,713 IT Pros & Developers. It's quick & easy.

pySerial- need help.

P: n/a
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.

--
regards,
kamarudin samsudin
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
kamarudin samsudin wrote:
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
Jul 18 '05 #2

P: n/a
Joal Heagney wrote:
kamarudin samsudin wrote:
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.)
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

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.