With this Python script I am getting errors:

import webiopi
import math 

GPIO = webiopi.GPIO

# Left motor GPIOs

# Right motor GPIOs

def left_stop():
    GPIO.output(L1, GPIO.LOW)
    GPIO.output(L2, GPIO.LOW)

def left_forward():
    GPIO.output(L1, GPIO.HIGH)
    GPIO.output(L2, GPIO.LOW)

def left_backward():
    GPIO.output(L1, GPIO.LOW)
    GPIO.output(L2, GPIO.HIGH)

def right_stop():
    GPIO.output(R1, GPIO.LOW)
    GPIO.output(R2, GPIO.LOW)

def right_forward():
    GPIO.output(R1, GPIO.HIGH)
    GPIO.output(R2, GPIO.LOW)

def right_backward():
    GPIO.output(R1, GPIO.LOW)
    GPIO.output(R2, GPIO.HIGH)

def go_forward():

def go_backward():

def turn_left():

def turn_right():

def stop():

# Setup GPIOs
GPIO.setFunction(L1, GPIO.OUT)
GPIO.setFunction(L2, GPIO.OUT)

GPIO.setFunction(R1, GPIO.OUT)
GPIO.setFunction(R2, GPIO.OUT)


server = webiopi.Server(port=8000, login="webiopi", password="raspberry")




# Reset GPIO functions

GPIO.setFunction(L1, GPIO.IN)
GPIO.setFunction(L2, GPIO.IN)

GPIO.setFunction(R1, GPIO.IN)
GPIO.setFunction(R2, GPIO.IN)

On execution I'm getting this:

file "script.py", line 7, in <module>
GPIO = webiopi.GPIO

AttributeError : module object has no attribute 'GPIO'

What is going wrong?

  • Check that webiopi and GPIO have been correctly spelled (e.g. no 0 instead of O). Check that you don't have file called webiopi.py or webiopi.pyc in the same directory as your script (unless it is the webiopi module). – joan Feb 11 '16 at 18:40

If you are using a Raspberry Pi 2 Model B, have you changed the reference to BCM2708 in your /WebIOPi-0.7.1/python/native directory?

If not, from the /WebIOPi-0.7.1 directory

  • cd into /python/native
  • Use your preferred editor to open the file named cpuinfo.c (For example, nano cpuinfo.c)
  • Page down until you see the reference for BCM2708 . If you see this, change it to BCM2709.
  • Save and exit.

In the same directory, open up the file named gpio.c (For example, nano gpio.c)

Look for the line that reads:

#define BCM2708_PERI_BASE 0x20000000

and modify this line to read

#define BCM2708_PERI_BASE 0x3f000000

Save and exit this file.

Head back up to your root WebIOPi directory

cd ..
cd ..

Now, run your setup file again with sudo ./setup.sh

This may or may not be your issue but I had to do this when upgrading to the RPI 2 and using WebIOPi.

Additional information: Edited to add more troubleshooting. If the above does not solve your issues, let's dig deeper.
From the command line, stop the WebIOPi service if it is running.
sudo /etc/init.d/webiopi stop Start the WebIOPi service again with verbose output and error notifications.
sudo webiopi -d -c /etc/webiopi/config
If you read the output you can generally find a lot of your problems here. I've found that your error can mean that WebIOPi is having the issue and not your script. Please reply back and let me know what the output is.

| improve this answer | |
  • Hi, Welcome to Pi Exchange and thank you fo providing an answer. I edited your answer and used markup to format your question. Although <br> works, generally a white line, code block or quote reads better during edit. – Piotr Kula Feb 11 '16 at 22:59
  • i tried this already. it didn't work. it showed attribute error again. please help me out. using raspberry pi2, webiopi-0.7.1 – shubham bhuyan Feb 13 '16 at 17:46

Hi I tried this Patch for Raspberry Pi 2. I have a Raspberry Pi 2 Model B and I followed the README manual and My WebIOPi actually works. This will definitely work according to my assumptions.

NOTE : This will work for WebIOPi-0.7.1 on a Raspberry Pi-2 Model B with 1 GB RAM

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.