Issue #130 [New/open] - NameError: global name 'GPIO' is not defined

Posted by istvanzk

What steps will reproduce the problem?

  1. Installation as described at: https://code.google.com/p/webiopi/wiki/INSTALL
  2. Run server in debug mode with: sudo webiopi -d -c /etc/webiopi/config
  3. Login/authentication via webrowser on local network: http://xxx.xxx.xxx.xxx:8000/
  4. Accessing http://xxx.xxx.xxx.xxx:8000/app/gpio-header

WebIOPi version used? => 0.7.0

Python version used? => 3.2

Distro used? (WebIOPi has only been tested on Raspbian Wheezy) => Raspbian

Raspberry Pi board revision? (1 or 2) => B (not B+)

For Javascript side bugs, Browser? => No JS errors. Firefox 33.1.1 on Mac OS X

Please provide any additional information below.

The GPIO.py and GPIO.cpython-32mu.so module is compiled correctly and are available in: /usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.0-py3.2-linux-armv6l.egg/_webiopi/

--- Log message listing ---

2014-11-29 19:13:07 - WebIOPi - INFO - Starting WebIOPi/0.7.0/Python3.2 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.digitalCount to REST GET /GPIO/count 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.digitalRead to REST GET /GPIO/%(channel)d/value 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.digitalWrite to REST POST /GPIO/%(channel)d/value/%(value)d 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.getFunctionString to REST GET /GPIO/%(channel)d/function 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.getPulse to REST GET /GPIO/%(channel)d/pulse 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.outputSequence to REST POST /GPIO/%(channel)d/sequence/%(args)s 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.portRead to REST GET /GPIO/*/integer 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.portWrite to REST POST /GPIO/*/integer/%(value)d 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.pulse to REST POST /GPIO/%(channel)d/pulse/ 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.pulseAngle to REST POST /GPIO/%(channel)d/pulseAngle/%(value)f 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.pulseRatio to REST POST /GPIO/%(channel)d/pulseRatio/%(value)f 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.setFunctionString to REST POST /GPIO/%(channel)d/function/%(value)s 2014-11-29 19:13:07 - WebIOPi - DEBUG - Mapping GPIO.wildcard to REST GET /GPIO/* 2014-11-29 19:13:07 - WebIOPi - INFO - GPIO - Native mapped to REST API /GPIO 2014-11-29 19:13:07 - WebIOPi - INFO - Loading configuration from /etc/webiopi/config 2014-11-29 19:13:07 - WebIOPi - INFO - Access protected using /etc/webiopi/passwd 2014-11-29 19:13:07 - WebIOPi - INFO - HTTP Server binded on http://192.168.87.110:8000/ 2014-11-29 19:13:07 - WebIOPi - INFO - CoAP Server binded on coap://224.0.1.123:5683/ (MULTICAST) 2014-11-29 19:13:07 - WebIOPi - INFO - CoAP Server binded on coap://192.168.87.110:5683/ 2014-11-29 19:13:14 - HTTP - DEBUG - "GET /app/gpio-header HTTP/1.1" - 200 OK (Client: 192.168.87.103 <Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:33.0) Gecko/20100101 Firefox/33.0>) 2014-11-29 19:13:14 - HTTP - DEBUG - "GET /webiopi.js HTTP/1.1" - 200 OK (Client: 192.168.87.103 <Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:33.0) Gecko/20100101 Firefox/33.0>) 2014-11-29 19:13:14 - HTTP - DEBUG - "GET /jquery.js HTTP/1.1" - 200 OK (Client: 192.168.87.103 <Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:33.0) Gecko/20100101 Firefox/33.0>) 2014-11-29 19:13:14 - HTTP - DEBUG - "GET /webiopi.css HTTP/1.1" - 200 OK (Client: 192.168.87.103 <Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:33.0) Gecko/20100101 Firefox/33.0>)

2014-11-29 19:13:14 - HTTP - DEBUG - "GET /map HTTP/1.1" - 200 OK (Client: 192.168.87.103 <Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:33.0) Gecko/20100101 Firefox/33.0>)

Exception happened during processing of request from ('192.168.87.103', 54645) Traceback (most recent call last): File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.0-py3.2-linux-armv6l.egg/webiopi/protocols/http.py", line 238, in processRequest result = self.server.handler.do_GET(relativePath, compact) File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.0-py3.2-linux-armv6l.egg/webiopi/protocols/rest.py", line 147, in do_GET return (200, self.getJSON(compact), M_JSON) File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.0-py3.2-linux-armv6l.egg/webiopi/protocols/rest.py", line 245, in getJSON gpios[gpio][f] = GPIO.getFunctionString(gpio) NameError: global name 'GPIO' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.2/socketserver.py", line 295, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib/python3.2/socketserver.py", line 321, in process_request self.finish_request(request, client_address) File "/usr/lib/python3.2/socketserver.py", line 334, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python3.2/socketserver.py", line 648, in __init__ self.handle() File "/usr/lib/python3.2/http/server.py", line 396, in handle self.handle_one_request() File "/usr/lib/python3.2/http/server.py", line 384, in handle_one_request method() File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.0-py3.2-linux-armv6l.egg/webiopi/protocols/http.py", line 267, in do_GET self.processRequest() File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.0-py3.2-linux-armv6l.egg/webiopi/protocols/http.py", line 258, in processRequest except (GPIO.InvalidDirectionException, GPIO.InvalidChannelException, GPIO.SetupException) as e: NameError: global name 'GPIO' is not defined


Comment 2

Posted by istvanzk

This is the same error as described in issue #97 and I fixed as described in the comment #4 of issue #97 (https://code.google.com/p/webiopi/issues/detail?id=97#c4).


Comment 3

Posted by jo@raspython.org

Here is a solution: http://www.raspython.org/webiopi-a-simple-but-great-web-api-for-the-raspberry-pi/