pySerial- need help.

Joal Heagney joal at bigpond.net.au
Thu Mar 31 20:43:06 EST 2005


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



More information about the Python-list mailing list