8 Replies - 244 Views - Last Post: 07 August 2014 - 05:43 PM Rate Topic: -----

#1 trilliansounds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-August 14

Notifier instance has no attribute 'growl'

Posted 07 August 2014 - 11:58 AM

Hi,

I'm new to python, inherited this code which forwards a message to skype and I was trying to add another forwarder to growl using GNTP.notifier but the following code spits out "AttributeError: Notifier instance has no attribute 'growl'". Can anyone help?


import BaseHTTPServer
import cgi
import os
import Skype4Py
import gntp.notifier
import time
import re

skype = Skype4Py.Skype()

# set skype (username removed for this forum)
user = ""

time.sleep(10) # delays for 10 seconds

class Notifier(BaseHTTPServer.BaseHTTPRequestHandler):
	server_version= "Notifier/0.1"
	def do_OPTIONS(self):
		self.send_response(200)
		self.send_header('Access-Control-Allow-Origin', '*')
		self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
		self.send_header("Access-Control-Allow-Headers", "X-Requested-With")

	def do_POST(self):
		length = int(self.headers.getheader('Content-length'))
		# Get the message
		post_vars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
		message = ' '.join(post_vars['message'])
		messageregex = re.sub('^(00|0?[1-9]|1[0-9]|2[0-3])\:(/>/>[0-5][0-9])\:(/>/>[0-5][0-9])', '', message)
		# relay the message via Skype
		self.notifySkype(messageregex)
		# relay the message via Growl
		self.sendtoGrowl(message)
		# Send the response
		self.send_response(200)
		self.send_header('Access-Control-Allow-Origin', '*')
		self.end_headers()
		growl = gntpnotifier.GrowlNotifier(
		applicationName = "My Application Name",
		notifications = ["New Updates","New Messages"],
		defaultNotifications = ["New Messages"],
		)
		growl.register()
	
	def notifySkype(self, messageregex):
		skype.SendMessage(user, messageregex)
	
	def sendtoGrowl(self, message):
	# 	gntp.notifier.mini(message)
	#   gntp.notifier.mini(message) works but I'd like to change the message priority
	#   following the example here http://pythonhosted.org/gntp/
	#   with this code though I get the error "Notifier instance has no attribute 'growl'
		self.growl.notify(
		noteType = "messages", 
			title = "messages", 
			description = message,
			priority=-1
		)

def connectSkype():
	if not skype.Client.IsRunning:
		print("Skype not running. Starting...")
		skype.Client.Start()
	else:
		print("Skype detected")

	print("Attaching to Skype... (This can take up to a minute)")
	skype.Attach()

def httpd(handler_class=Notifier, 
server_address = ('', 4002)):
	http_server = BaseHTTPServer.HTTPServer(server_address, handler_class)
	print("Listening for messages... Ready!")
	http_server.serve_forever()

if __name__ == "__main__":
	connectSkype()
	httpd()




Is This A Good Question/Topic? 0
  • +

Replies To: Notifier instance has no attribute 'growl'

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,417
  • Joined: 12-December 12

Re: Notifier instance has no attribute 'growl'

Posted 07 August 2014 - 12:13 PM

What code did you add to the working code? And what line does the error message refer to, in your posted code? Added: Oh I see that you've added a comment into the code - it's clearer if you mention this in your topic-text.

This post has been edited by andrewsw: 07 August 2014 - 12:15 PM

Was This Post Helpful? 0
  • +
  • -

#3 trilliansounds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-August 14

Re: Notifier instance has no attribute 'growl'

Posted 07 August 2014 - 12:48 PM

View Postandrewsw, on 07 August 2014 - 12:13 PM, said:

What code did you add to the working code? And what line does the error message refer to, in your posted code? Added: Oh I see that you've added a comment into the code - it's clearer if you mention this in your topic-text.


Hi, the error message refers to line 53 and I've added lines 5, 33, 38-43, 48-58 to the original code
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,417
  • Joined: 12-December 12

Re: Notifier instance has no attribute 'growl'

Posted 07 August 2014 - 01:10 PM

I'll guess that line 38 should be
    self.growl = gntp.notifie... etc

and line 43
    self.growl.register()

Without 'self' you are creating a local variable, which isn't available to other methods, hence why 'growl' is not available as an attribute.

This post has been edited by andrewsw: 07 August 2014 - 01:12 PM

Was This Post Helpful? 0
  • +
  • -

#5 trilliansounds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-August 14

Re: Notifier instance has no attribute 'growl'

Posted 07 August 2014 - 04:24 PM

Still getting the error message "notifier instance has no attribute 'growl'"

The full traceback is as follows:

Quote

File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", 321, in process_request
self.finish_request(request, client_address)
"C:\Python27\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
"C:\Python27\lib\SocketServer.py", line 649, in __init__
self.handle()
"C:\Python27\lib\BaseHTTPServer.py", line 340, in handle


here's the revised code:

import BaseHTTPServer
import cgi
import os
import Skype4Py
import gntp.notifier
import time
import re

skype = Skype4Py.Skype()

# set skype (username removed for this forum)
user = ""

time.sleep(10) # delays for 10 seconds

class Notifier(BaseHTTPServer.BaseHTTPRequestHandler):
	server_version= "Notifier/0.1"
	def do_OPTIONS(self):
		self.send_response(200)
		self.send_header('Access-Control-Allow-Origin', '*')
		self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
		self.send_header("Access-Control-Allow-Headers", "X-Requested-With")

	def do_POST(self):
		length = int(self.headers.getheader('Content-length'))
		# Get the message
		post_vars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
		message = ' '.join(post_vars['message'])
		messageregex = re.sub('^(00|0?[1-9]|1[0-9]|2[0-3])\:(/>[0-5][0-9])\:(/>[0-5][0-9])', '', message)
		# relay the message via Skype
		self.notifySkype(messageregex)
		# relay the message via Growl
		self.sendtoGrowl(message)
		# Send the response
		self.send_response(200)
		self.send_header('Access-Control-Allow-Origin', '*')
		self.end_headers()
		self.growl = gntp.notifier.GrowlNotifier( #<---- updated
		applicationName = "My Application Name",
		notifications = ["New Updates","New Messages"],
		defaultNotifications = ["New Messages"],
		)
		self.growl.register() #<---- updated
	
	def notifySkype(self, messageregex):
		skype.SendMessage(user, messageregex)
	
	def sendtoGrowl(self, message):
	# 	gntp.notifier.mini(message)
	#   gntp.notifier.mini(message) works but I'd like to change the message priority
	#   following the example here http://pythonhosted.org/gntp/
	#   with this code though I get the error "Notifier instance has no attribute 'growl'
		self.growl.notify( #<---- updated
		noteType = "messages", 
			title = "messages", 
			description = message,
			priority=-1
		)

def connectSkype():
	if not skype.Client.IsRunning:
		print("Skype not running. Starting...")
		skype.Client.Start()
	else:
		print("Skype detected")

	print("Attaching to Skype... (This can take up to a minute)")
	skype.Attach()

def httpd(handler_class=Notifier, 
server_address = ('', 4002)):
	http_server = BaseHTTPServer.HTTPServer(server_address, handler_class)
	print("Listening for messages... Ready!")
	http_server.serve_forever()

if __name__ == "__main__":
	connectSkype()
	httpd()


This post has been edited by andrewsw: 07 August 2014 - 04:31 PM
Reason for edit:: Fixed tags

Was This Post Helpful? 0
  • +
  • -

#6 trilliansounds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-August 14

Re: Notifier instance has no attribute 'growl'

Posted 07 August 2014 - 04:33 PM

Apologies for the double post (I hit the reply button early and can't see an edit button), here's the traceback:

File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
  self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", 321, in process_request
  self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
  self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 649, in __init__
  self.handle()
File "C:\Python27\lib\BaseHTTPServer.py", line 340, in handle
  self.handle_one_request()
File "C:\Python27\Scripts\NotifierScript.py", line 33 in do_POST
  self.sendtoGrowl(message)
File "C:\Python27\Scripts\NotifierScript.py", line 53, in sendtoGrowl
  self.growl.notify(
AttributeError: Notifier instance has no attribute 'growl'



And the revised script:

import BaseHTTPServer
import cgi
import os
import Skype4Py
import gntp.notifier
import time
import re

skype = Skype4Py.Skype()

# set skype (username removed for this forum)
user = ""

time.sleep(10) # delays for 10 seconds

class Notifier(BaseHTTPServer.BaseHTTPRequestHandler):
	server_version= "Notifier/0.1"
	def do_OPTIONS(self):
		self.send_response(200)
		self.send_header('Access-Control-Allow-Origin', '*')
		self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
		self.send_header("Access-Control-Allow-Headers", "X-Requested-With")

	def do_POST(self):
		length = int(self.headers.getheader('Content-length'))
		# Get the message
		post_vars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
		message = ' '.join(post_vars['message'])
		messageregex = re.sub('^(00|0?[1-9]|1[0-9]|2[0-3])\:(/>/>/>/>/>[0-5][0-9])\:(/>/>/>/>/>[0-5][0-9])', '', message)
		# relay the message via Skype
		self.notifySkype(messageregex)
		# relay the message via Growl
		self.sendtoGrowl(message)
		# Send the response
		self.send_response(200)
		self.send_header('Access-Control-Allow-Origin', '*')
		self.end_headers()
		self.growl = gntp.notifier.GrowlNotifier( #<---- updated
		applicationName = "My Application Name",
		notifications = ["New Updates","New Messages"],
		defaultNotifications = ["New Messages"],
		)
		self.growl.register() #<---- updated
	
	def notifySkype(self, messageregex):
		skype.SendMessage(user, messageregex)
	
	def sendtoGrowl(self, message):
	# 	gntp.notifier.mini(message)
	#   gntp.notifier.mini(message) works but I'd like to change the message priority
	#   following the example here http://pythonhosted.org/gntp/
	#   with this code though I get the error "Notifier instance has no attribute 'growl'
		self.growl.notify( #<---- updated
		noteType = "messages", 
			title = "messages", 
			description = message,
			priority=-1
		)

def connectSkype():
	if not skype.Client.IsRunning:
		print("Skype not running. Starting...")
		skype.Client.Start()
	else:
		print("Skype detected")

	print("Attaching to Skype... (This can take up to a minute)")
	skype.Attach()

def httpd(handler_class=Notifier, 
server_address = ('', 4002)):
	http_server = BaseHTTPServer.HTTPServer(server_address, handler_class)
	print("Listening for messages... Ready!")
	http_server.serve_forever()

if __name__ == "__main__":
	connectSkype()
	httpd()


Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,417
  • Joined: 12-December 12

Re: Notifier instance has no attribute 'growl'

Posted 07 August 2014 - 04:46 PM

I know nothing about these modules but your do_POST method calls sendToGrowl before growl has been assigned - line 33 is before line 38. The sendToGrowl method refers to self.growl on line 53.. but it hasn't been defined yet.
Was This Post Helpful? 0
  • +
  • -

#8 trilliansounds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-August 14

Re: Notifier instance has no attribute 'growl'

Posted 07 August 2014 - 05:40 PM

View Postandrewsw, on 07 August 2014 - 04:46 PM, said:

I know nothing about these modules but your do_POST method calls sendToGrowl before growl has been assigned - line 33 is before line 38. The sendToGrowl method refers to self.growl on line 53.. but it hasn't been defined yet.


Thanks, getting there. The traceback message has now changed to:

File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
  self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", 321, in process_request
  self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
  self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 649, in __init__
  self.handle()
File "C:\Python27\lib\BaseHTTPServer.py", line 340, in handle
  self.handle_one_request()
File "C:\Python27\lib\BaseHTTPServer.py", line 340, in handle_one_request
  method()
File "C:\Python27\Scripts\NotifierScript.py", line 43 in do_POST
  self.sendtoGrowl(message)
File "C:\Python27\Scripts\NotifierScript.py", line 57, in sendtoGrowl
  priority=-1
File "C:\Python27\lib\site-packages\gntp\notifier.py", line 118, in notify
  assert noteType in self.notifications
Assertion Error





import BaseHTTPServer
import cgi
import os
import Skype4Py
import gntp.notifier
import time
import re

skype = Skype4Py.Skype()

# set skype (username removed for this forum)
user = ""

time.sleep(10) # delays for 10 seconds

class Notifier(BaseHTTPServer.BaseHTTPRequestHandler):
	server_version= "Notifier/0.1"
	def do_OPTIONS(self):
		self.send_response(200)
		self.send_header('Access-Control-Allow-Origin', '*')
		self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
		self.send_header("Access-Control-Allow-Headers", "X-Requested-With")

	def do_POST(self):
		length = int(self.headers.getheader('Content-length'))
		# Get the message
		post_vars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
		message = ' '.join(post_vars['message'])
		messageregex = re.sub('^(00|0?[1-9]|1[0-9]|2[0-3])\:(/>/>/>/>/>/>/>/>/>[0-5][0-9])\:(/>/>/>/>/>/>/>/>/>[0-5][0-9])', '', message)
		# relay the message via Skype
		self.notifySkype(messageregex)
		# Send the response
		self.send_response(200)
		self.send_header('Access-Control-Allow-Origin', '*')
		self.end_headers()
		self.growl = gntp.notifier.GrowlNotifier(
		applicationName = "My Application Name",
		notifications = ["New Updates","New Messages"],
		defaultNotifications = ["New Messages"],
		)
		self.growl.register()
		# relay the message via Growl
		self.sendtoGrowl(message)#<---- moved
	
	def notifySkype(self, messageregex):
		skype.SendMessage(user, messageregex)
	
	def sendtoGrowl(self, message):
	# 	gntp.notifier.mini(message)
	#   gntp.notifier.mini(message) works but I'd like to change the message priority
	#   following the example here http://pythonhosted.org/gntp/
	#   with this code though I get the error "Notifier instance has no attribute 'growl'
		self.growl.notify(
		noteType = "messages", 
			title = "messages", 
			description = message,
			priority=-1
		)

def connectSkype():
	if not skype.Client.IsRunning:
		print("Skype not running. Starting...")
		skype.Client.Start()
	else:
		print("Skype detected")

	print("Attaching to Skype... (This can take up to a minute)")
	skype.Attach()

def httpd(handler_class=Notifier, 
server_address = ('', 4002)):
	http_server = BaseHTTPServer.HTTPServer(server_address, handler_class)
	print("Listening for messages... Ready!")
	http_server.serve_forever()

if __name__ == "__main__":
	connectSkype()
	httpd()




Just re-reading the complete example on http://pythonhosted.org/gntp/

I changed line 53 from
priority=-1



to
priority = -1,



Still no luck.
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,417
  • Joined: 12-December 12

Re: Notifier instance has no attribute 'growl'

Posted 07 August 2014 - 05:43 PM

I will guess again that your noteType is incorrect, because it is not a notification that you have registered:
self.growl.notify(
    noteType = "messages",

It should be "New Messages".

GNTP Basics :the docs
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1