Page 1 of 1

cannot load auth module

Posted: Mon Mar 18, 2013 10:09 pm
by drapacioli
Hi, I've spent the last month trying to set up my pi, get an irc client that works for my needs, and set up proper remote access, and I thought I was finally in the clear once I got everything working, except now I'm running into issues with the following python scripts and was wondering if I could get some help trying to figure out what the issue is. This is a script that provides authorization to connect to a server using a specialized key and passcode, but I keep getting an importerror when I try to load the scripts:

Code: Select all

import socket
import string
import auth

# Variables
_host = "75.126.194.90"
_port = 6667
_channels = "%#TheLobby"
_debug = True

# Misc function(s)
def doSend(str):
	s.send("%s\r\n" % (str))
	if _debug:
		print "-> " + str

# Begin auth/connection
try:
	# First we get our authcode
	_auth = auth.getAPI("authcode")
	if _auth != "ERR":
		# Authcode is fine, proceed with server connection
		s = socket.socket()
		s.connect((_host, _port))
		doSend("AUTH OAServPassport I :OASSP000000X1A")
		_buffer = ""
		while 1:
			_buffer = _buffer + s.recv(1024)
			temp = string.split(_buffer, "\n")
			_buffer = temp.pop()
			for line in temp:
				line = string.rstrip(line)
				param = string.split(line)
				if _debug:
					print "<- " + line

				if param[0][0] == ":":
					if param[1] == "005":
						# Tell the server we're an IRCx client
						doSend("IRCX")
						# Join channel(s)
						if _channels != "":
							doSend("CREATE %s" % (_channels))
				else:

					if param[0] == "PING":
						doSend("PONG")
					elif param[0] == "AUTH":
						if param[2] == "S":
							if param[3] == ":OK":
								# Lets send auth code
								doSend("AUTH OAServPassport S :%s" % (_auth))
							else:
								# Lets send challenge response
								_cx= auth.getAPI("challenge", param[3][12:])
								if _cx != "ERR":
									doSend("AUTH OAServPassport S :OASSP000000%s" % (_cx))
	else:
		print "API error!"
except:
	print "Connection error!"
and this is the second part:

Code: Select all

__module_name__ = "auth.py"
__module_version__ = "1.0"
__module_description__ = "Test"

import urllib
import re
import time
from hashlib import sha1
import hmac
import binascii
import md5


## API DATA
_api_key = "API KEY REMOVED"
_api_pass = "API PASS REMOVED"

## DO NOT EDIT BELOW
_time = time.time()

def makeJSON():
	json = "{\"timestamp\":%d}" % (_time)
	hashed = hmac.new(_api_pass, json, sha1)
	return md5.new(binascii.b2a_base64(hashed.digest())[:-1]).hexdigest()

def getAPI(type, code = ""):
	link = "https://www.oasiz.com/api?api_key=%s&access_token=%s&timestamp=%d&api_call=" % (_api_key, makeJSON(), _time)
	sock = urllib.urlopen("%sircx_%s&query=%s" % (link, type, code))
	html = sock.read()
	sock.close()
	m = re.compile(r'%s": "(.*?)"' % (type)).search(html)
	try:
		v = m.group(1)
	except:
		v = "ERR"
	return v
If I load the first one it seems to work (I get no error, yet no confirmation), but for the second one I get this:

Traceback (most recent call last):
File: "home/pi/OasizPy/bot.py", line 3, in <module>
import auth
ImportError: No module named auth
Error loading module /home/pi/OasizPy/bot.py

I did a bit of looking, first I tried adding the module_name bit to see if that would fix it but it did not, so I did more searching and apparently this is a library that is supposedly included in python 2.6? I did an apt-get for python and sure enough I already have it, but I also did an apt-get for a module I found called web-auth.py which is apparently linked to auth.py, sure enough there was a package version to install, but it made no difference. What else can I try to get this script to work?

For reference I'm running a standard Pi install, running the recommended Wheezy OS, ssh and vnc through ssh tunnel, nothing really installed as of yet but I made sure everything was up to date. I can't say I know enough about these python scripts to troubleshoot them myself, I am a beginner in programming and only really know basic stuff in java, but I think I have a basic understanding of what I'm looking at (maybe...)

Re: cannot load auth module

Posted: Wed Mar 20, 2013 8:49 am
by cae2100
try cd'ing into the folder with the program/library and running the program from there, might help then. also make sure the library file is in the same folder as the main program.

Re: cannot load auth module

Posted: Wed Mar 20, 2013 4:40 pm
by drapacioli
I'll assume you mean the plugins folder in /usr/lib/xchat? I just tried that, same result. Thanks for the suggestion though, I didn't think to move it there myself :P. I also tried moving it into the hidden /.xchat2 folder in the user directory, as that was another place that popped up in the sidebar when I went to the load a script menu.

Is there a verbose mode or debugger I could use to find out exactly where the program is looking to call the auth module? That might be a good help but I'm unfamiliar with how I would find such a setting or feature.

Re: cannot load auth module

Posted: Wed Mar 20, 2013 5:51 pm
by cae2100
I meant having the auth.py file in the same folder as your program, unless you installed it using "sudo python setup.py install" command.

Re: cannot load auth module

Posted: Wed Mar 20, 2013 6:18 pm
by drapacioli
I'm afraid I don't understand. I installed xchat using apt-get, I'm not sure where exactly it installs it. I'm not sure where python is installed either, it's the version that comes with the Raspbian install image. Both should be in default locations (wherever that is), but I don't know linux so I have no idea where that might be.

Also, bot.py is in the same folder as auth.py. I moved both every time I tried a different location.

Wait I see what you mean, I had to use that sudo python auth.py install command to get the script to find it? I think it worked, I'll try to connect it now.

EDIT: Still did not work.

Re: cannot load auth module

Posted: Sun Mar 24, 2013 8:36 pm
by drapacioli
I have been unable to make any new progress on my own, does anyone else know what might be up?

Re: cannot load auth module

Posted: Sun Mar 24, 2013 9:46 pm
by cae2100
I'd change the name of auth.py file to something else, like chatauth.py and call that instead since it's supposed to be included, maybe it's trying to load something else and it's countering with another file. Another thing I'd check is auth.py's spelling, and caps, if it has any caps in it, it has to be spelled like that when you call it, like RPI.GPIO compared to rpi.gpio.

Re: cannot load auth module

Posted: Tue Mar 26, 2013 6:31 am
by drapacioli
Thanks for the idea, I had not thought of that. Unfortunately changing the name did not make a difference :(

Re: cannot load auth module

Posted: Tue Mar 26, 2013 10:09 am
by cae2100
last question, what python are you using? 2.x or 3.x?
bc the problem may be that your opening it in 3x and it running only in 2.x
also, how are you trying to open the program, through the command line or through IDLE. some things have issues when run through idle, but will work fine when startng from command line.

Re: cannot load auth module

Posted: Tue Mar 26, 2013 10:55 pm
by drapacioli
to be honest I'm not sure. I start xchat through the terminal then use the load script option in the program to try loading the scripts, the auth one loads fine I suppose (no error messages), but the bot.py script fails to load as previously noted. I just tried loading the scripts themselves through the terminal with verbose mode on, bot.py threw an API arror, maybe this makes sense to someone?

Code: Select all

pi@raspberrypi ~/.xchat2 $ python -v bot.py
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib/python2.7/site.pyc matches /usr/lib/python2.7/site.py
import site # precompiled from /usr/lib/python2.7/site.pyc
# /usr/lib/python2.7/os.pyc matches /usr/lib/python2.7/os.py
import os # precompiled from /usr/lib/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /usr/lib/python2.7/posixpath.pyc matches /usr/lib/python2.7/posixpath.py
import posixpath # precompiled from /usr/lib/python2.7/posixpath.pyc
# /usr/lib/python2.7/stat.pyc matches /usr/lib/python2.7/stat.py
import stat # precompiled from /usr/lib/python2.7/stat.pyc
# /usr/lib/python2.7/genericpath.pyc matches /usr/lib/python2.7/genericpath.py
import genericpath # precompiled from /usr/lib/python2.7/genericpath.pyc
# /usr/lib/python2.7/warnings.pyc matches /usr/lib/python2.7/warnings.py
import warnings # precompiled from /usr/lib/python2.7/warnings.pyc
# /usr/lib/python2.7/linecache.pyc matches /usr/lib/python2.7/linecache.py
import linecache # precompiled from /usr/lib/python2.7/linecache.pyc
# /usr/lib/python2.7/types.pyc matches /usr/lib/python2.7/types.py
import types # precompiled from /usr/lib/python2.7/types.pyc
# /usr/lib/python2.7/UserDict.pyc matches /usr/lib/python2.7/UserDict.py
import UserDict # precompiled from /usr/lib/python2.7/UserDict.pyc
# /usr/lib/python2.7/_abcoll.pyc matches /usr/lib/python2.7/_abcoll.py
import _abcoll # precompiled from /usr/lib/python2.7/_abcoll.pyc
# /usr/lib/python2.7/abc.pyc matches /usr/lib/python2.7/abc.py
import abc # precompiled from /usr/lib/python2.7/abc.pyc
# /usr/lib/python2.7/_weakrefset.pyc matches /usr/lib/python2.7/_weakrefset.py
import _weakrefset # precompiled from /usr/lib/python2.7/_weakrefset.pyc
import _weakref # builtin
# /usr/lib/python2.7/copy_reg.pyc matches /usr/lib/python2.7/copy_reg.py
import copy_reg # precompiled from /usr/lib/python2.7/copy_reg.pyc
# /usr/lib/python2.7/traceback.pyc matches /usr/lib/python2.7/traceback.py
import traceback # precompiled from /usr/lib/python2.7/traceback.pyc
# /usr/lib/python2.7/sysconfig.pyc matches /usr/lib/python2.7/sysconfig.py
import sysconfig # precompiled from /usr/lib/python2.7/sysconfig.pyc
# /usr/lib/python2.7/re.pyc matches /usr/lib/python2.7/re.py
import re # precompiled from /usr/lib/python2.7/re.pyc
# /usr/lib/python2.7/sre_compile.pyc matches /usr/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/lib/python2.7/sre_parse.pyc matches /usr/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/lib/python2.7/sre_parse.pyc
# /usr/lib/python2.7/sre_constants.pyc matches /usr/lib/python2.7/sre_constants.py
import sre_constants # precompiled from /usr/lib/python2.7/sre_constants.pyc
# /usr/lib/python2.7/_sysconfigdata.pyc matches /usr/lib/python2.7/_sysconfigdata.py
import _sysconfigdata # precompiled from /usr/lib/python2.7/_sysconfigdata.pyc
# /usr/lib/python2.7/_sysconfigdata_nd.pyc matches /usr/lib/python2.7/_sysconfigdata_nd.py
import _sysconfigdata_nd # precompiled from /usr/lib/python2.7/_sysconfigdata_nd.pyc
# /usr/lib/python2.7/sitecustomize.pyc matches /usr/lib/python2.7/sitecustomize.py
import sitecustomize # precompiled from /usr/lib/python2.7/sitecustomize.pyc
import encodings # directory /usr/lib/python2.7/encodings
# /usr/lib/python2.7/encodings/__init__.pyc matches /usr/lib/python2.7/encodings/__init__.py
import encodings # precompiled from /usr/lib/python2.7/encodings/__init__.pyc
# /usr/lib/python2.7/codecs.pyc matches /usr/lib/python2.7/codecs.py
import codecs # precompiled from /usr/lib/python2.7/codecs.pyc
import _codecs # builtin
# /usr/lib/python2.7/encodings/aliases.pyc matches /usr/lib/python2.7/encodings/aliases.py
import encodings.aliases # precompiled from /usr/lib/python2.7/encodings/aliases.pyc
# /usr/lib/python2.7/encodings/utf_8.pyc matches /usr/lib/python2.7/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/lib/python2.7/encodings/utf_8.pyc
Python 2.7.3 (default, Jan 13 2013, 11:20:46) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
# /usr/lib/python2.7/urllib.pyc matches /usr/lib/python2.7/urllib.py
import urllib # precompiled from /usr/lib/python2.7/urllib.pyc
# /usr/lib/python2.7/string.pyc matches /usr/lib/python2.7/string.py
import string # precompiled from /usr/lib/python2.7/string.pyc
import strop # builtin
# /usr/lib/python2.7/socket.pyc matches /usr/lib/python2.7/socket.py
import socket # precompiled from /usr/lib/python2.7/socket.pyc
import _socket # builtin
# /usr/lib/python2.7/functools.pyc matches /usr/lib/python2.7/functools.py
import functools # precompiled from /usr/lib/python2.7/functools.pyc
import _functools # builtin
dlopen("/usr/lib/python2.7/lib-dynload/_ssl.so", 2);
import _ssl # dynamically loaded from /usr/lib/python2.7/lib-dynload/_ssl.so
import cStringIO # builtin
import time # builtin
# /usr/lib/python2.7/base64.pyc matches /usr/lib/python2.7/base64.py
import base64 # precompiled from /usr/lib/python2.7/base64.pyc
# /usr/lib/python2.7/struct.pyc matches /usr/lib/python2.7/struct.py
import struct # precompiled from /usr/lib/python2.7/struct.pyc
import _struct # builtin
import binascii # builtin
# /usr/lib/python2.7/urlparse.pyc matches /usr/lib/python2.7/urlparse.py
import urlparse # precompiled from /usr/lib/python2.7/urlparse.pyc
# /usr/lib/python2.7/collections.pyc matches /usr/lib/python2.7/collections.py
import collections # precompiled from /usr/lib/python2.7/collections.pyc
import _collections # builtin
import operator # builtin
# /usr/lib/python2.7/keyword.pyc matches /usr/lib/python2.7/keyword.py
import keyword # precompiled from /usr/lib/python2.7/keyword.pyc
# /usr/lib/python2.7/heapq.pyc matches /usr/lib/python2.7/heapq.py
import heapq # precompiled from /usr/lib/python2.7/heapq.pyc
import itertools # builtin
# /usr/lib/python2.7/bisect.pyc matches /usr/lib/python2.7/bisect.py
import bisect # precompiled from /usr/lib/python2.7/bisect.pyc
import _bisect # builtin
import _heapq # builtin
import thread # builtin
# /usr/lib/python2.7/ssl.pyc matches /usr/lib/python2.7/ssl.py
import ssl # precompiled from /usr/lib/python2.7/ssl.pyc
# /usr/lib/python2.7/textwrap.pyc matches /usr/lib/python2.7/textwrap.py
import textwrap # precompiled from /usr/lib/python2.7/textwrap.pyc
# /usr/lib/python2.7/hashlib.pyc matches /usr/lib/python2.7/hashlib.py
import hashlib # precompiled from /usr/lib/python2.7/hashlib.pyc
dlopen("/usr/lib/python2.7/lib-dynload/_hashlib.so", 2);
import _hashlib # dynamically loaded from /usr/lib/python2.7/lib-dynload/_hashlib.so
# /usr/lib/python2.7/hmac.pyc matches /usr/lib/python2.7/hmac.py
import hmac # precompiled from /usr/lib/python2.7/hmac.pyc
# /usr/lib/python2.7/md5.pyc matches /usr/lib/python2.7/md5.py
import md5 # precompiled from /usr/lib/python2.7/md5.pyc
# /home/pi/.xchat2/authtesting.pyc matches /home/pi/.xchat2/authtesting.py
import authtesting # precompiled from /home/pi/.xchat2/authtesting.pyc
# /home/pi/.xchat2/auth.pyc matches /home/pi/.xchat2/auth.py
import auth # precompiled from /home/pi/.xchat2/auth.pyc
# /usr/lib/python2.7/httplib.pyc matches /usr/lib/python2.7/httplib.py
import httplib # precompiled from /usr/lib/python2.7/httplib.pyc
import array # builtin
# /usr/lib/python2.7/mimetools.pyc matches /usr/lib/python2.7/mimetools.py
import mimetools # precompiled from /usr/lib/python2.7/mimetools.pyc
# /usr/lib/python2.7/tempfile.pyc matches /usr/lib/python2.7/tempfile.py
import tempfile # precompiled from /usr/lib/python2.7/tempfile.pyc
# /usr/lib/python2.7/random.pyc matches /usr/lib/python2.7/random.py
import random # precompiled from /usr/lib/python2.7/random.pyc
# /usr/lib/python2.7/__future__.pyc matches /usr/lib/python2.7/__future__.py
import __future__ # precompiled from /usr/lib/python2.7/__future__.pyc
import math # builtin
import _random # builtin
import fcntl # builtin
# /usr/lib/python2.7/rfc822.pyc matches /usr/lib/python2.7/rfc822.py
import rfc822 # precompiled from /usr/lib/python2.7/rfc822.pyc
API error!
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear sys.exc_traceback
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# clear sys.flags
# clear sys.float_info
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup __main__
# cleanup[1] cStringIO
# cleanup[1] _collections
# cleanup[1] functools
# cleanup[1] encodings
# cleanup[1] site
# cleanup[1] sysconfig
# cleanup[1] httplib
# cleanup[1] operator
# cleanup[1] array
# cleanup[1] math
# cleanup[1] _heapq
# cleanup[1] __future__
# cleanup[1] abc
# cleanup[1] _bisect
# cleanup[1] _weakrefset
# cleanup[1] sre_constants
# cleanup[1] collections
# cleanup[1] _codecs
# cleanup[1] _struct
# cleanup[1] _warnings
# cleanup[1] authtesting
# cleanup[1] zipimport
# cleanup[1] _sysconfigdata
# cleanup[1] encodings.utf_8
# cleanup[1] auth
# cleanup[1] codecs
# cleanup[1] _sysconfigdata_nd
# cleanup[1] strop
# cleanup[1] _functools
# cleanup[1] sitecustomize
# cleanup[1] keyword
# cleanup[1] signal
# cleanup[1] traceback
# cleanup[1] hmac
# cleanup[1] urlparse
# cleanup[1] itertools
# cleanup[1] posix
# cleanup[1] encodings.aliases
# cleanup[1] exceptions
# cleanup[1] _weakref
# cleanup[1] random
# cleanup[1] mimetools
# cleanup[1] heapq
# cleanup[1] _random
# cleanup[1] tempfile
# cleanup[1] urllib
# cleanup[1] md5
# cleanup[1] fcntl
# cleanup[1] rfc822
# cleanup[1] ssl
# cleanup[1] hashlib
# cleanup[1] socket
# cleanup[1] bisect
# cleanup[1] time
# cleanup[1] base64
# cleanup[1] _hashlib
# cleanup[1] thread
# cleanup[1] _ssl
# cleanup[1] _socket
# cleanup[1] binascii
# cleanup[1] struct
# cleanup[1] textwrap
# cleanup[1] string
# cleanup[1] re
# cleanup[1] sre_compile
# cleanup[1] _sre
# cleanup[1] sre_parse
# cleanup[2] copy_reg
# cleanup[2] posixpath
# cleanup[2] errno
# cleanup[2] _abcoll
# cleanup[2] types
# cleanup[2] genericpath
# cleanup[2] stat
# cleanup[2] warnings
# cleanup[2] UserDict
# cleanup[2] os.path
# cleanup[2] linecache
# cleanup[2] os
# cleanup sys
# cleanup __builtin__
# cleanup ints: 41 unfreed ints
# cleanup floats: 31 unfreed floats
Is this any help? I'm pretty sure it's running python 2.7 in the terminal, but I don't know what version of of python xchat uses to run the scripts itself.

Re: cannot load auth module

Posted: Wed Apr 10, 2013 3:03 pm
by drapacioli
Anyone have any ideas? I've had absolutely no luck with this....