+ 3
Help with Pubnub
I am trying to use Pubnub to build a security camera using a pi zero but i am running into problems at the very start. The tutorials on the website are not without mistakes and not up to date for The RPi3. Also i would like to use python3, insteat of 2. the error i get is: TypeError: 'module' object is not callable
6 Answers
+ 3
Hi Davy,
On your RPi3 run:
pip install pubnub
You'll want to start with the basics first. So before reading further try this out: https://gist.github.com/stephenlb/33722e268b3f12c969d90f3ae40244fe
import pubnub#pubnub==4.0.2
import time
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
pnconf = PNConfiguration()
pnconf.subscribe_key = "demo"
pnconf.publish_key = "demo"
pubnub = PubNub(pnconf)
def show(msg, stat):
if msg and stat: print( msg.timetoken, stat.status_code )
else : print( "Error", stat and stat.status_code )
while True:
pubnub.publish().channel("logging").message("hello").async(show)
time.sleep(2)
This should work for Python2. It's not likely to work with Python 3. For Python 3, you may consider using the code found here: https://github.com/pubnub/python/tree/python3
It is best to stick with Python 2 for now. And Python 3 code isn't fully supported yet.
Here is a GIST I made a while back. It uses GPIO for Python 2 which works with Raspberry Pi
https://gist.github.com/stephenlb/518b8312393d43c23336791105c4ac6f
+ 7
https://stackoverflow.com/questions/4534438/typeerror-module-object-is-not-callable#4534443
+ 1
thanks guys. i will let you know if i can get it to work.
+ 1
This error statement TypeError: 'module' object is not callable is raised as you are being confused about the Class name and Module name. The problem is in the import line . You are importing a module, not a class. This happend because the module name and class name have the same name .
If you have a class "MyClass" in a file called "MyClass.py" , then you should import :
from MyClass import MyClass
In Python , a script is a module, whose name is determined by the filename . So when you start out your file MyClass.py with import MyClass you are creating a loop in the module structure.
In Python, everything (including functions, methods, modules, classes etc.) is an object , and methods are just attributes like every others. So,there's no separate namespaces for methods. So when you set an instance attribute, it shadows the class attribute by the same name. The obvious solution is to give attributes different names.
More...
http://net-informations.com/python/iq/typeerror.htm
0
Finally...
Used
pip3 install pubnub
to get pubnub library available for python3
got lots of help from:
https://www.pubnub.com/docs/JUMP_LINK__&&__python__&&__JUMP_LINK/data-streams-publish-and-subscribe
and from you guys.
I wiil insert the scripts soon.