473,320 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

pySerial- need help.

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
2 4109
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
0
by: xunling | last post by:
i have a question about answering ..... this topic is "need help" what do i have to write at te topic line, !after i have klicked the "answer message" button ive tried many possibilities,...
2
by: Paul Mendez | last post by:
I really need some help Date Code ConCAT Bal_Fwd NS_Fees Amt_Coll Cur_End_Bal 1/15/2004 KW 11KW2003 $500.00 $250.00 $250.00 2/15/2004 KW 12KW2003 $300.00 $500.00 ...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
8
by: Elliot M. Rodriguez | last post by:
I am having a heckuva time debugging this, or determining why my page is behaving this way. I have a search form, that when completed, returns a datagrid. When the user selects a row (normal...
3
by: Rich Squid | last post by:
Hello Here's my basic problem: On my asp.net form page I have a DetailsView (default mode=edit) bound to a AccessDataSource control. Users can successfuly update a databound template field,...
2
by: XML Beginner | last post by:
I have an XML file that contains values that my application needs, so it knows which database to connect to. It also contains a configuration option so that I can specify which node to return...
2
by: =?Utf-8?B?am9lb2ppaA==?= | last post by:
Most students do not have enough time to do their homeworks, assignments, college papers, etc alone. Also most of them, even though they know what to do with respect to their writing assignment,...
1
by: jhaydon | last post by:
First of all, I'm not a CSS expert. If I was, I wouldn't need to be posting for help here. Secondly, I have been doing web design for several years, just not css. Thirdly, I need help and hope...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.