Ticket Error: <class 'serial.serialutil.SerialException'> could not open port /dev/ttyAMA0:

721 views
Skip to first unread message

theoffi...@gmail.com

unread,
Mar 14, 2013, 3:30:38 AM3/14/13
to web...@googlegroups.com

Hello guys,


i hope someone can help me with this! i have been stuck here for days. I just created a web app using web2py and i want to use it to send some serial commands to a device through Raspberry Pi. 

I have successfully sent the commands from R-Pi to the device by running a Python script in the terminal.

But i thought web2py is using python as well so i did something similar but i get the error below:

<class 'serial.serialutil.SerialException'> could not open port /dev/ttyAMA0: [Errno 13] Permission denied: '/dev/ttyAMA0'


my codes are:

in Controller:


def test():

    import serial

    serialport= serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5)

return dict() <-- not sure what to return

in view/default/index.html:

<a href = "{{=URL(c='default', f='test')}}"><img src ="/Comfort2/static/images/off.jpg" width ="75" height="75"</a>

i created a default/test.html as well. 


i have no idea what's wrong! :( give me some hints please. thank you!

Niphlod

unread,
Mar 14, 2013, 4:24:36 AM3/14/13
to web...@googlegroups.com
did you check that the user running your "working" script is the same as the one running the "I'm going wrong" web2py ?

The Organisation of Secret Shoppers

unread,
Mar 14, 2013, 11:41:25 PM3/14/13
to web...@googlegroups.com
hmm how do i check? i think running the python script has to be "root" user? but i'm not sure what is the user type for the web2py...


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/tiWZkXMoo6E/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Christian Foster Howes

unread,
Mar 15, 2013, 3:33:44 AM3/15/13
to web...@googlegroups.com
the "user" for web2py depends on how you launch it...

if you call:

python web2py.py

then it runs as you

if you:

sudo su bob
python web2py.py

it runs a bob.

if you use apache or some other server i believe by default it runs as the user that is running apache.

The Organisation of Secret Shoppers

unread,
Mar 15, 2013, 4:28:09 AM3/15/13
to web...@googlegroups.com
so do you mean i must edit my controller and views from the terminal? (currently i'm editing them through the web) and the current application was created using application wizard, which i think it said that it have to be modified in the wizard itself.

Niphlod

unread,
Mar 15, 2013, 4:35:06 AM3/15/13
to web...@googlegroups.com
it's fine, but what you need to check is for the user who started the web2py process to be able to use your /dev/serialwhatever interface....
How did you install web2py ?

PS: I have a raspberry too :P

Massimo Di Pierro

unread,
Mar 15, 2013, 9:40:41 AM3/15/13
to web...@googlegroups.com
One solution is discussed here:


It is not the most secure solution but should get you going for debugging purposes.

Another solution, better, suggested here

"add the dialout group the the www-data user"

Massimo

The Organisation of Secret Shoppers

unread,
Mar 18, 2013, 3:00:37 AM3/18/13
to web...@googlegroups.com
ahh i installed web2py on my R-pi by this way:

wget http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh
chmod +x setup-web2py-ubuntu.sh

./setup-web2py-ubuntu.sh

:D

The Organisation of Secret Shoppers

unread,
Mar 18, 2013, 3:04:28 AM3/18/13
to web...@googlegroups.com
Thank you Massimo :D I will try it out! and Thank you for developing such an awesome application!! :)

The Organisation of Secret Shoppers

unread,
Mar 25, 2013, 11:17:29 PM3/25/13
to web...@googlegroups.com
Dear Massimo, i have tried those methods from the articles suggested by you previously. However I am still getting the same error.
I have also tried to copy the "Serial" folder from python2.7 dist-packages to web2py site-packages. the result is still the same.
Bellow is the detail of the error ticket. Please help me take a look and tell me what's wrong. thank you so much for your kind patience in helping me.

Ticket ID

10.0.0.190.2013-03-26.09-37-15.161acac2-83f7-447d-b0f4-7acd40b6497e

<class 'serial.serialutil.SerialException'> could not open port /dev/ttyAMA0: [Errno 13] Permission denied: '/dev/ttyAMA0'

Version

web2py™ (2, 4, 2, 'stable', datetime.datetime(2013, 3, 4, 3, 26, 21))
Python Python 2.7.3: /usr/bin/python (prefix: /usr)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
Traceback (most recent call last):
File "/home/www-data/web2py/gluon/restricted.py", line 212, in restricted
exec ccode in environment
File "/home/www-data/web2py/applications/Comfort2/controllers/default.py", line 27, in <module>
File "/home/www-data/web2py/gluon/globals.py", line 193, in <lambda>
self._caller = lambda f: f()
File "/home/www-data/web2py/applications/Comfort2/controllers/default.py", line 19, in test
serialport= serial.Serial("/dev/ttyAMA0", 9600, timeout=1)
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
self.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 276, in open
raise SerialException("could not open port %s: %s" % (self._port, msg))
SerialException: could not open port /dev/ttyAMA0: [Errno 13] Permission denied: '/dev/ttyAMA0'

Reply all
Reply to author
Forward
0 new messages