[Tutor] python 2.6 and MySQL fail

2010-01-30 Thread Rayon
I have installed python 2.6.4 on my windows7 laptop and MySQL dB. 

Every time I try to import the module I get this error. 

 

File "C:\Python26\lib\site-packages\MySQLdb\__init__.py", line 19, in


import _mysql

ImportError: DLL load failed: The specified module could not be found.

 

I need to know why and if there is a fix I can use.

This  works fine on python2.5. 

 

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] cherrypy

2010-04-13 Thread Rayon
I am running cherrypy server but I am having some trouble with sessions 

 

Where is my code 

 

from cherrypy.lib import sessions

sess = sessions.Session()

x = sess.id 

 

 

return x; 

 

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] module import problems

2010-04-25 Thread Rayon
I have a module with the name _table 
in the same directory I have another by the name of _module

I would like to import _table into _module

can someone tall me how. 

from tables.report_db_engine import *











___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] module import problems

2010-04-26 Thread Rayon
I have a project folder  report_db in that project folder I have to  packages 
_modules and _ tables

report_db   \
_tables 
_modules 
  I want to import some functions from _tables  to _modules so I can use them 
in  a function in _modules.

  


From: bob gailer 
Sent: Sunday, April 25, 2010 10:25 PM
To: tutor@python.org 
Subject: Re: [Tutor] module import problems


On 4/25/2010 9:56 PM, Rayon wrote: 
  I have a module with the name _table 
  in the same directory I have another by the name of _module

  I would like to import _table into _module

What exactly does that mean?

The import statement, when executed,  imports a module into the module 
containing the import statement.

And what is the purpose of the following line?


  from tables.report_db_engine import *




-- 
Bob Gailer
919-636-4239
Chapel Hill NC




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] module import problems

2010-04-26 Thread Rayon
my bad it was a simple error I was calling it form the wrong module thanks


From: Rayon 
Sent: Monday, April 26, 2010 3:47 AM
To: bob gailer ; tutor@python.org 
Subject: Re: [Tutor] module import problems


I have a project folder  report_db in that project folder I have to  packages 
_modules and _ tables

report_db   \
_tables 
_modules 
  I want to import some functions from _tables  to _modules so I can use them 
in  a function in _modules.

  


From: bob gailer 
Sent: Sunday, April 25, 2010 10:25 PM
To: tutor@python.org 
Subject: Re: [Tutor] module import problems


On 4/25/2010 9:56 PM, Rayon wrote: 
  I have a module with the name _table 
  in the same directory I have another by the name of _module

  I would like to import _table into _module

What exactly does that mean?

The import statement, when executed,  imports a module into the module 
containing the import statement.

And what is the purpose of the following line?


  from tables.report_db_engine import *




-- 
Bob Gailer
919-636-4239
Chapel Hill NC




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor






___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problem with cherrypy

2010-05-24 Thread Rayon
I am trying to get  and set some session variables in ram with cherrypy 

 

Here is my code: 

 

import cherrypy

 

 

#cherry.session.get('user')

#cherry.session.get('password')

 



def security(f):

cherry.session.get('user')   

cherry.session.get('password')

 

 

error message: 

AttributeError: 'module' object has no attribute 'session'

 

Could some one plz help me  

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problems with cherrypy sessions

2010-05-24 Thread Rayon
Here is the code I am not sure why this is not working I have sessions
turned on. 

 

import cherrypy

 

 

 

@cherrypy.expose   

def security(f):

cherrypy.session.get('id')

return f



 

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python telnet

2009-08-19 Thread Rayon
using python telnet lib to connect to a Nortel switch, and dump some tables. 
My problem is that every now and then the connection is reset by peer . 
Telnet Error : (10054, Connection reset by peer)
I need  to know why, I have it in a loop so it will download after a few tries 
but I need to know why. 
here is the code. 


#main telnet class
import telnetlib
#import telnet lib

class supertelnet: # super tenet class


def __init__(self): # def construct
""

def telNetCall(self, Host, User, Pass, LocalFile):
print "start lens dump"
host  = Host
user  = User
password = Pass
file = LocalFile
telnet  = telnetlib.Telnet(host) # connect to telnet client
#telnet.set_debuglevel(1)
telnet.read_until('Enter User Name', 3) # read session data untill 
match or timeout.
telnet.write(user + '\r') # send username
telnet.write(password + '\r') #send password
# send command to dump len files
# start
print "lens dump in progress"
telnet.write('table ibnlines' + '\r')
telnet.write('format pack' + '\r')
telnet.write('list all' + '\r')
telnet.write('logout' + '\r')
#end of commands
lens =  telnet.read_all() # get session data and store data
print "file write strated"
x = open(file,'wd') # open file
x.write(lens) # write data to file
print "file done"___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] max min value in array

2009-09-17 Thread Rayon
I need to find the max and min value from some floats in a array:
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] order data

2009-09-18 Thread Rayon
I have a array with this data in it 

0.0046,0.095,0.0904,521456,['MCI 521456 0.0904'],['ATT 521 0.0919'],['IDT 521 
0.095'],['None']
0.0083,0.0192,0.0109,39023821,['MCI 39023821 0.0109'],['ATT 39 0.012'],['IDT 39 
0.0192'],['SPR 39 0.0135']
0.0421,0.0681,0.026,73462,['MCI 73462 0.0260'],['ATT 7 0.026'],['IDT 73462 
0.028'],['SPR 7 0.0681']
0.0176,0.1035,0.0859,126872,['MCI 126872 0.0859'],['ATT 1268 0.0919'],['IDT 
126872 0.1035'],['None']
0.0215,0.1614,0.1399,5032130,['MCI 5032130 0.1614'],['ATT 5032130 
0.1399'],['IDT 503 0.152'],['None']
0.0206,0.0385,0.0179,1868,['MCI 1868 0.0179'],['ATT 1868 0.0385'],['IDT 1868 
0.036'],['None']
0.0325,0.087,0.0545,5027889,['MCI 5027889 0.0602'],['ATT 5027889 0.0545'],['IDT 
502 0.087'],['None']
0.0325,0.087,0.0545,5027888,['MCI 5027888 0.0602'],['ATT 5027888 0.0545'],['IDT 
502 0.087'],['None']
0.0046,0.095,0.0904,521455,['MCI 521455 0.0904'],['ATT 521 0.0919'],['IDT 521 
0.095'],['None']
0.1292,0.1762,0.047,5989,['MCI 5989 0.1762'],['ATT 598 0.05'],['IDT 5989 
0.173'],['SPR 598 0.047']
0.0706,0.2011,0.1305,1284499,['MCI 1284499 0.2011'],['ATT 1284499 
0.1932'],['IDT 1284499 0.1305'],['None']


and I want to order the display of that data by the second row.
can I do it in this array from or do I have to break it down more. 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how can I append a iteration to a tow dimensional array

2009-09-19 Thread Rayon
how can I append a iteration to a tow dimensional array 
so that one value can be like a key in a dir. 

I can't use a directory because some of the values repeat and the dir throws 
them out. 


def getMark(record):
for x in record.split(','):
return str(x).strip()

array = []
for x in  bigMethod():
   array.append(getMark(x))
array1=[]
for count in array:
 array1 = [[count],[x]]
for v in array1:
print v___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] list sort problem

2009-09-19 Thread Rayon
ok so here it is I think  this one should be very clear:

I have some data in a list, the data in question: 

0.0046,0.095,0.0904,521456,['MCI 521456 0.0904'],['ATT 521 0.0919'],['IDT 521 
0.095'],['None']
0.0083,0.0192,0.0109,39023821,['MCI 39023821 0.0109'],['ATT 39 0.012'],['IDT 39 
0.0192'],['SPR 39 0.0135']
0.042,0.0681,0.026,73462,['MCI 73462 0.0260'],['ATT 7 0.026'],['IDT 73462 
0.028'],['SPR 7 0.0681']
0.0176,0.1035,0.0859,126872,['MCI 126872 0.0859'],['ATT 1268 0.0919'],['IDT 
126872 0.1035'],['None']
0.0215,0.1614,0.1399,5032130,['MCI 5032130 0.1614'],['ATT 5032130 
0.1399'],['IDT 503 0.152'],['None']
0.0206,0.0385,0.0179,1868,['MCI 1868 0.0179'],['ATT 1868 0.0385'],['IDT 1868 
0.036'],['None']
0.0325,0.087,0.0545,5027889,['MCI 5027889 0.0602'],['ATT 5027889 0.0545'],['IDT 
502 0.087'],['None']
0.0325,0.087,0.0545,5027888,['MCI 5027888 0.0602'],['ATT 5027888 0.0545'],['IDT 
502 0.087'],['None']
0.0046,0.095,0.0904,521455,['MCI 521455 0.0904'],['ATT 521 0.0919'],['IDT 521 
0.095'],['None']
0.1292,0.1762,0.047,5989,['MCI 5989 0.1762'],['ATT 598 0.05'],['IDT 5989 
0.173'],['SPR 598 0.047']
0.0706,0.2011,0.1305,1284499,['MCI 1284499 0.2011'],['ATT 1284499 
0.1932'],['IDT 1284499 0.1305'],['None']
0.0325,0.087,0.0545,5027881,['MCI 5027881 0.0602'],['ATT 5027881 0.0545'],['IDT 
502 0.087'],['None']

my problem is that I want to order it by the first item so for line number one 
that would be  0.0046: 
this value is not unique it might repeat, if the last 10 values like this that 
might be the same and there are the lowest in the over list. 
I want them first when I display this list and the bigger  values after in 
order is size.  

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list sort problem solved

2009-09-20 Thread Rayon

list = bigMethod() # this method makes the list

list.sort() # here is the sort thanks
for x in list: # out put the sort
   print x

it all works Thanks a lot
--
From: "Dave Angel" 
Sent: Saturday, September 19, 2009 7:46 PM
To: "Rayon" 
Cc: 
Subject: Re: [Tutor] list sort problem


Rayon wrote:

ok so here it is I think  this one should be very clear:

I have some data in a list, the data in question:
0.0046,0.095,0.0904,521456,['MCI 521456 0.0904'],['ATT 521 0.0919'],['IDT 
521 0.095'],['None']
0.0083,0.0192,0.0109,39023821,['MCI 39023821 0.0109'],['ATT 39 
0.012'],['IDT 39 0.0192'],['SPR 39 0.0135']
0.042,0.0681,0.026,73462,['MCI 73462 0.0260'],['ATT 7 0.026'],['IDT 73462 
0.028'],['SPR 7 0.0681']
0.0176,0.1035,0.0859,126872,['MCI 126872 0.0859'],['ATT 1268 
0.0919'],['IDT 126872 0.1035'],['None']
0.0215,0.1614,0.1399,5032130,['MCI 5032130 0.1614'],['ATT 5032130 
0.1399'],['IDT 503 0.152'],['None']
0.0206,0.0385,0.0179,1868,['MCI 1868 0.0179'],['ATT 1868 0.0385'],['IDT 
1868 0.036'],['None']
0.0325,0.087,0.0545,5027889,['MCI 5027889 0.0602'],['ATT 5027889 
0.0545'],['IDT 502 0.087'],['None']
0.0325,0.087,0.0545,5027888,['MCI 5027888 0.0602'],['ATT 5027888 
0.0545'],['IDT 502 0.087'],['None']
0.0046,0.095,0.0904,521455,['MCI 521455 0.0904'],['ATT 521 0.0919'],['IDT 
521 0.095'],['None']
0.1292,0.1762,0.047,5989,['MCI 5989 0.1762'],['ATT 598 0.05'],['IDT 5989 
0.173'],['SPR 598 0.047']
0.0706,0.2011,0.1305,1284499,['MCI 1284499 0.2011'],['ATT 1284499 
0.1932'],['IDT 1284499 0.1305'],['None']
0.0325,0.087,0.0545,5027881,['MCI 5027881 0.0602'],['ATT 5027881 
0.0545'],['IDT 502 0.087'],['None']


my problem is that I want to order it by the first item so for line 
number one that would be  0.0046: this value is not unique it might 
repeat, if the last 10 values like this that might be the same and there 
are the lowest in the over list. I want them first when I display this 
list and the bigger  values after in order is size.




I'll have to make some assumptions, please correct or confirm them.

Each line of your message represents one item in a list.  Each such item 
is in turn a sublist.


Each of these sublists contains 3 floats, an int, and a few more 
subsublists


Each of these subsublists contains a string

Anyway, you want to sort the top-level list.  Since the first item in each 
sublist is a float, by default they will be ordered by the first item, 
which is what you're asking for.  In case of a collision, the second item 
is examined, and so on.


 mylist.sort()
will sort the list in-place, based on the first element of each item in 
the list



mylist = []
mylist.append( [0.0046,0.095,0.0904,521456,['MCI 521456 0.0904'],['ATT 521 
0.0919'],['IDT 521 0.095'],['None']])
mylist.append( [0.0083,0.0192,0.0109,39023821,['MCI 39023821 
0.0109'],['ATT 39 0.012'],['IDT 39 0.0192'],['SPR 39 0.0135']])
mylist.append( [0.042,0.0681,0.026,73462,['MCI 73462 0.0260'],['ATT 7 
0.026'],['IDT 73462 0.028'],['SPR 7 0.0681']])
mylist.append( [0.0176,0.1035,0.0859,126872,['MCI 126872 0.0859'],['ATT 
1268 0.0919'],['IDT 126872 0.1035'],['None']])
mylist.append( [0.0215,0.1614,0.1399,5032130,['MCI 5032130 0.1614'],['ATT 
5032130 0.1399'],['IDT 503 0.152'],['None']])
mylist.append( [0.0206,0.0385,0.0179,1868,['MCI 1868 0.0179'],['ATT 1868 
0.0385'],['IDT 1868 0.036'],['None']])
mylist.append( [0.0325,0.087,0.0545,5027889,['MCI 5027889 0.0602'],['ATT 
5027889 0.0545'],['IDT 502 0.087'],['None']])
mylist.append( [0.0325,0.087,0.0545,5027888,['MCI 5027888 0.0602'],['ATT 
5027888 0.0545'],['IDT 502 0.087'],['None']])
mylist.append( [0.0046,0.095,0.0904,521455,['MCI 521455 0.0904'],['ATT 521 
0.0919'],['IDT 521 0.095'],['None']])
mylist.append( [0.1292,0.1762,0.047,5989,['MCI 5989 0.1762'],['ATT 598 
0.05'],['IDT 5989 0.173'],['SPR 598 0.047']])
mylist.append( [0.0706,0.2011,0.1305,1284499,['MCI 1284499 0.2011'],['ATT 
1284499 0.1932'],['IDT 1284499 0.1305'],['None']])
mylist.append( [0.0325,0.087,0.0545,5027881,['MCI 5027881 0.0602'],['ATT 
5027881 0.0545'],['IDT 502 0.087'],['None']])


def show_list_partial(thelist):
   for item in thelist:
   print item[0], item[1]

show_list_partial(mylist)
mylist.sort()
print ""
show_list_partial(mylist)


DaveA.




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] mod_python authentication

2009-12-05 Thread Rayon
I need to  setup a login page for a web application but I am not finding any
code in the mod_python doc that shows me how to do this. 

What is need is the code to tell apache to get this login data from a login
page. 

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] mod_python authentication

2009-12-05 Thread Rayon
I need to  setup a login page for a web application but I am not finding any
code in the mod_python doc that shows me how to do this. 

What is need is the code to tell apache to get this login data from a login
page. 

 

OTOH if you want to build your own login system (e.g. with user details
stored in a database) then you:

1) Make a regular HTML form with username and password fields

2) Write whatever login processing code you need, and have the form submit
to it.

3) Check for an active login session on every page that requires
authentication, and redirect them back to the login form if necessary.

 

 

 

I need to know how to configure the httpd file to allow for this al so. 

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] mod_python authentication

2009-12-06 Thread Rayon
how to check whether a user is authenticated with mod_python

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] mod_python authentication

2009-12-07 Thread Rayon
How do I Check for an active login session on every page that requires
authentication

 

Been at this for days and it's holding me back can someone  plz help me with
some code examples. 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] printing xps or gif

2009-12-31 Thread Rayon
Can I use python to print xps or gif.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python telnet slow down.

2010-12-29 Thread Rayon
Hi I need help with a some telnet automation I am trying build. 
I need to login to a Nortel switch and send a table dump command capture
that data and send it to I file. 
I have the code it, works and does all that I need my problem is that when I
try to dump a table later than 4 mega the it can take hours but when I use
cross talk and do it the manual way it takes 20 min. 
I need to know why and if there are any changes I can make to my code to fix
this. 



#!/usr/bin/env python

import telnetlib
#import telnet_hack

class Telnet_lib:

host = {'server':'','user':'','password':''}
commands = []
read_till = ''
capture_file =''

def fileopen(self,capture_file,data):
try:
  out_file = open(capture_file,"w")
  out_file.write(data)
except IOError,error:
print error


def gtt_telnet(self):
tn = telnetlib.Telnet(self.host['server'])
tn.set_debuglevel(100)
tn.read_until('Enter User Name', 3)
tn.write(self.host['user'] + "\r")
tn.read_until('Password: ', 3)
tn.write(self.host['password'] + "\r")
tn.read_until('HGUO0190.PPC4 V:103', 3)
for com in self.commands:
tn.write(com + "\r")
print 'dump starts'
tn.read_some()
#data = tn.read_until(self.read_till)
#self.fileopen(self.capture_file,data)
 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python file upload

2011-05-13 Thread Rayon
Hi all, 

I need a python script to upload a xml file to a web page using python. 

I have tried using pycurl but I am still getting errors. 

 

import urllib2

import pycurl

 

data="""











gtt_admin

Password2011



2001-11-15T13:18:08-08:00







738002000417469



Enterprise
B









"""

 

headers = ["Content-Type:text/xml"]

#data = open("d:\\dump\\activation.xml")

c = pycurl.Curl()

c.setopt(c.URL, "https://provisioning.etr.blackberry.net/ari/submitXML";)

c.setopt(pycurl.POST,1)

c.setopt(pycurl.SSL_VERIFYPEER, 0)

c.setopt(pycurl.SSL_VERIFYHOST, 0) 

c.setopt(pycurl.HTTPHEADER, headers)

c.setopt(pycurl.POSTFIELDS, data)

c.setopt(c.VERBOSE, 1)

c.perform()

c.close()

 

this is the error I am getting. 

* About to connect() to provisioning.etr.blackberry.net port 443 (#0)

*   Trying 216.9.243.178... * connected

* Connected to provisioning.etr.blackberry.net (216.9.243.178) port 443 (#0)

* libcurl is now using a weak random seed!

* SSL connection using RC4-MD5

* Server certificate:

*  subject: C=CA; ST=Ontario; L=Waterloo; O=Research In Motion
Limited; OU=IT; CN=provisioning.etr.blackberry.net

*  start date: 2011-03-28 00:00:00 GMT

*  expire date: 2012-03-27 23:59:59 GMT

*  issuer: C=US; O=Thawte, Inc.; CN=Thawte SSL CA

*  SSL certificate verify result: self signed certificate in
certificate chain (19), continuing anyway.

> POST /ari/submitXML HTTP/1.1 User-Agent: PycURL/7.19.7 Host:
provisioning.etr.blackberry.net Accept: */* Content-Type:text/xml
Content-Length: 836  < HTTP/1.1 500 Internal Server Error < Connection:
close < Date: Fri, 13 May 2011 18:35:24 GMT < Content-Length: 90 <
Content-Type: text/html < X-Powered-By: Servlet/2.5 JSP/2.1 <  * Closing
connection #0

ERROR_ID=PARSEING_ERROR

DESCRIPTION=Request parsing failed: Tag in line:2 Ending column:6

 

 

Regards Rayon

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] upload xml file via pycurl

2011-05-16 Thread Rayon
I am trying to upload a xml file via pycurl, I really need some help here. 

 

url = "https://192.168.0.68/fileupload/upload_file.php";

 

binaryptr = open('activation.xml','rb').read()

head = ['Content-type:text/xml']

c.setopt(c.SSL_VERIFYPEER, 0)

c.setopt(c.SSL_VERIFYHOST, 0)

c.setopt(c.POSTFIELDS,binaryptr)

c.setopt(c.POSTFIELDSIZE,23L)

c.setopt(c.HTTPHEADER,head)

c.setopt(c.URL, url)

c.setopt(c.VERBOSE, 1)

c.perform() 

 

Regards Rayon

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] need help with lxml errors

2011-05-22 Thread Rayon
I am trying to import lxml 

 

from lxml import etree

 

bb = etree.Element(self.get_time)

 return str(bb)

 

and I get this error:

 

File "C:\Python26\lib\site-packages\lxml\apihelpers.pxi", line 1480, in
lxml.etree.__getNsTag (src/lxml/lxml.etree.c:23373)

File "C:\Python26\lib\site-packages\lxml\apihelpers.pxi", line 1364, in
lxml.etree._utf8 (src/lxml/lxml.etree.c:22190)

TypeError: Argument must be bytes or unicode, got 'instancemethod'

 

Regards Rayon

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with lxml errors

2011-05-22 Thread Rayon
Wow I did not see that, long day and night :) thanks a lot.

Regards Rayon

-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Steven
D'Aprano
Sent: Sunday, May 22, 2011 8:23 AM
To: tutor@python.org
Subject: Re: [Tutor] need help with lxml errors

On Sun, 22 May 2011 09:51:44 pm Rayon wrote:
> I am trying to import lxml
>
> from lxml import etree

And that succeeds fine. Your problem lies elsewhere.

> bb = etree.Element(self.get_time)
>  return str(bb)

In future, please copy and paste (do NOT retype, simplify or summarize) the
full traceback you get, not just the error message.

In this case, I *think* I can *guess* your error, based on the error message
alone, but I could be completely off-base. But my guess is that you need:

bb = etree.Element(self.get_time())

rather than:

bb = etree.Element(self.get_time)

The later tries to insert a method get_time into the element tree. You need
to call the method by putting brackets () after it.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] telnet connection question

2011-06-09 Thread Rayon
HI All, 

Is there any way that I can use python telnetlib to connect to a telnet
session. 

Send commands and get back data without closing the connection. 

I need the response to be faster and the login process is taking up too much
time. 

 

I was thinking I could use a queue to pass in data but I am not sure how i
would get it out. 

 

Regards Rayon

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python telnet

2011-10-22 Thread Rayon
 

 

 

From: Rayon [mailto:ra...@gtt.co.gy] 
Sent: 21 October 2011 18:53
To: 'tutor@python.org'
Subject: python telnet

 

Can I connect to a telnet session and return data without disconnecting the
data session.  

 

Regards Rayon

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python telnet

2011-10-22 Thread Rayon
Well  what I am doing is connecting to a telnet session sending some
commands, exiting and returning some data. 
What  I would to do is send the commands and return the data without exiting
the session. 
I would like to keep the same session and just send commands and return
data.

#!/usr/bin/env python
import telnetlib

class hlr_com():

#get host and command 
def __init__(self):
"""init host and command  """
self.user_name = ''
self.password = '**'
self.host = '172.20.50.176'
self.command = ''

#edit top of return 
def fix_return(self,hia_return):
"""
edit the top of data returned form the hia
"""
try:
  data = str(hia_return).strip('\r')
  return data
except Exception,error:
   logs("error",str(err),'null')
 

#set host ip address
def set_host(self,host):
""" set host ipaddress"""
self.host = host

   

#send command to hia and end session
def hlr_telnet(self,command):
"""
connect to host and execute command and
exit
"""
try: 
hlr_tel = telnetlib.Telnet(self.host)
hlr_tel.read_until('login:')
hlr_tel.write(self.user_name+"\r")
hlr_tel.read_until('Password:')
hlr_tel.write(self.password+"\r")
#execute command 
hlr_tel.read_until('maint@atcaHLRds0 /public/users/maint>')
hlr_tel.write(command+'\r')
#end session
data = hlr_tel.read_until('maint@atcaHLRds0
/public/users/maint>')
hlr_tel.write('exit'+'\r')
data2 = self.fix_return(data)
#return data
return data2
except Exception,error:
logs("error",str(err),'null')

   
def logs(self,log_type,log_data,ip_address):
 """
 Log for errors 
 """
 try:
conn =
psycopg2.connect(database="hlr_proxy",user="postgres",host="localhost",
password="bb_server_1",port="5432") #connect to database
create_date = str(datetime.datetime.now())
cur = conn.cursor() # create cursor
cur.execute("insert into
hlr_logs(create_date,log_type,log_data,ip_address)values(%s,%s,%s,%s)",
(create_date,log_type,log_data,ip_address))
conn.commit()
cur.close()
conn.close()
 finally:
try: 
  log_file = open(r"text_log.txt","a")
 
log_file.write(create_date+","+log_type+","+log_data+","+str(ip_address)+'\r
'+'\n')
  log_file.close()
except Exception,error:
pass 








-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Steven
D'Aprano
Sent: 22 October 2011 15:55
To: tutor@python.org
Subject: Re: [Tutor] python telnet

Rayon wrote:

> Can I connect to a telnet session and return data without 
> disconnecting the data session.

Isn't this the same question you asked back in June?

We tried to answer your question then, did you see our responses, and were
they useful?

At the time, you were complaining that the telnet session was too slow, but
you didn't tell us what you were actually doing. David Heiserca took a guess
as to what you were doing, and suggested what you should do again. Did you
see his response, and was it helpful?

You should show us the code you are using.


--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python telnet

2011-10-22 Thread Rayon
Thanks  I will try it and post the code, looks like what I need.

-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Steven
D'Aprano
Sent: 22 October 2011 21:13
To: tutor@python.org
Subject: Re: [Tutor] python telnet

Rayon wrote:
> Well  what I am doing is connecting to a telnet session sending some 
> commands, exiting and returning some data.
> What  I would to do is send the commands and return the data without 
> exiting the session.
> I would like to keep the same session and just send commands and 
> return data.

Change the work-flow from:

repeatedly:-
   log in
   write data
   log out

to:

log in
repeatedly:
   write data
log out



This is untested, but it should point you in the right direction. For
brevity, anything unchanged will be left out.


#!/usr/bin/env python
import telnetlib

class hlr_com():
 #get host and command
 def __init__(self):
 """init host and command  """
 self.user_name = ''
 self.password = '**'
 self.host = '172.20.50.176'
 self.command = ''
 self._connected = False

 def fix_return(self,hia_return):
 # UNCHANGED FROM YOUR VERSION

 #set host ip address
 def set_host(self,host):
 # UNCHANGED FROM YOUR VERSION

 def connect(self):
 # If already connected, do nothing.
 if self._connected:
 return
 try:
 hlr_tel = telnetlib.Telnet(self.host)
 hlr_tel.read_until('login:')
 hlr_tel.write(self.user_name+"\r")
 hlr_tel.read_until('Password:')
 hlr_tel.write(self.password+"\r")
 self._connected = True
 except Exception,error:
 logs("error",str(err),'null')

 def execute(self, command):
 """execute command"""
 try:
 self._execute_or_fail(command)
 except Exception,error:
 logs("error",str(err),'null')

 def _execute_or_fail(self, command):
 if not self._connected:
 # This is probably the wrong exception type
 raise ValueError('you must connect first')
 # otherwise execute the command
 hlr_tel.read_until('maint@atcaHLRds0 /public/users/maint>')
 hlr_tel.write(command+'\r')

 def end_session(self):
 data = hlr_tel.read_until(
 'maint@atcaHLRds0 /public/users/maint>'
 )
 hlr_tel.write('exit'+'\r')
 data = self.fix_return(data)
 return data

 def logs(self,log_type,log_data,ip_address):
 # UNCHANGED FROM YOUR VERSION



To use it:


instance = hlr_com()
instance.connect()
instance.execute("fe")
instance.execute("fi")
instance.execute("fo")
instance.execute("fum")
instance.end_session()


As I said, untested. Good luck!



-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python telnet

2011-11-17 Thread Rayon
 

 

 

From: Rayon [mailto:ra...@gtt.co.gy] 
Sent: 17 November 2011 14:04
To: 'tutor@python.org'
Subject: python telnet 

 

I am trying to use winpexpect  to connect  a telnet session. 

I keep getting this  error. 

 

raise ExceptionPexpect, 'Command not found: %s' % self.command

ExceptionPexpect: Command not found: telnet

 

 

###code###

from winpexpect import winspawn

 

 

child = winspawn('telnet 192.168.0.55:210')

 

help me plz

Regards Rayon

 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python telnet

2011-11-18 Thread Rayon
I installed the telnet client but still the same error. 

Traceback (most recent call last):
  File "C:\Users\Rayon\Documents\projects1\super_hia\main.py", line 6, in

child = winspawn('telnet 192.168.0.55:210')
  File
"C:\Python26\lib\site-packages\winpexpect-1.5-py2.6.egg\winpexpect.py", line
346, in __init__
logfile=logfile, cwd=cwd, env=env)
  File "C:\Python26\lib\site-packages\winpexpect-1.5-py2.6.egg\pexpect.py",
line 429, in __init__
self._spawn (command, args)
  File
"C:\Python26\lib\site-packages\winpexpect-1.5-py2.6.egg\winpexpect.py", line
369, in _spawn
raise ExceptionPexpect, 'Command not found: %s' % self.command
ExceptionPexpect: Command not found: telnet 

-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Steven
D'Aprano
Sent: 17 November 2011 19:52
To: tutor@python.org
Subject: Re: [Tutor] python telnet

Rayon wrote:

> I am trying to use winpexpect  to connect  a telnet session. 
> I keep getting this  error. 
> 
>  
> 
> raise ExceptionPexpect, 'Command not found: %s' % self.command
> ExceptionPexpect: Command not found: telnet

Please copy and paste the entire traceback, not just the last couple of
lines. But judging by just the small bit you show, it looks like "telnet" is
not a command that winpexpect understands, so it raises an error "command
not found".

Perhaps it is a bug in winpexpect. Are you using the latest version?

Do you actually have telnet available on your system? If not, then you can't
expect winpexpect to use something which isn't there.


-- 
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python telnet

2011-11-18 Thread Rayon
Thank you I think I understand now, thank you very much.

-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Steven
D'Aprano
Sent: 17 November 2011 19:52
To: tutor@python.org
Subject: Re: [Tutor] python telnet

Rayon wrote:

> I am trying to use winpexpect  to connect  a telnet session. 
> I keep getting this  error. 
> 
>  
> 
> raise ExceptionPexpect, 'Command not found: %s' % self.command
> ExceptionPexpect: Command not found: telnet

Please copy and paste the entire traceback, not just the last couple of
lines. But judging by just the small bit you show, it looks like "telnet" is
not a command that winpexpect understands, so it raises an error "command
not found".

Perhaps it is a bug in winpexpect. Are you using the latest version?

Do you actually have telnet available on your system? If not, then you can't
expect winpexpect to use something which isn't there.


-- 
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python telnet

2011-11-19 Thread Rayon
I used the turn on turn off feature, and I can start a telnet session from
the command line. 

-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Steven
D'Aprano
Sent: 19 November 2011 07:04
To: tutor@python.org
Subject: Re: [Tutor] python telnet

Rayon wrote:
> I installed the telnet client but still the same error. 

How did you install it? Windows includes a telnet application, but it has to
be enabled first:

http://windows.microsoft.com/en-AU/windows-vista/Telnet-frequently-asked-que
stions

If you run "telnet" from the Windows shell (cmd.exe), what happens?

Until you can successfully run telnet from Windows, there isn't any point
trying to run it from Python.


-- 
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python telnet

2011-11-19 Thread Rayon
Thanks but still not working, I am wondering if I need to give the script
some kind of special permission to execute on windows 7.

-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of James
Chapman
Sent: 19 November 2011 08:23
To: tutor@python.org
Subject: Re: [Tutor] python telnet

traceback has:
 child = winspawn('telnet 192.168.0.55:210')

When using telnet from CLI (on windows), you would type:
telnet 192.168.0.55 210

Note the space between the IP and port number and not a :colon.

Not sure this is your problem but probably worth mentioning.

--
James


At Saturday, 19/11/2011 on 11:44 Rayon wrote:
> I used the turn on turn off feature, and I can start a telnet session 
> from the command line.
> 
> -Original Message-
> From: tutor-bounces+evosweet=hotmail@python.org
> [mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of 
> Steven D'Aprano
> Sent: 19 November 2011 07:04
> To: tutor@python.org
> Subject: Re: [Tutor] python telnet
> 
> Rayon wrote:
> > I installed the telnet client but still the same error. 
> 
> How did you install it? Windows includes a telnet application, but it 
> has to be enabled first:
> 
> http://windows.microsoft.com/en-AU/windows-vista/Telnet-frequently-ask
> ed-que
> stions
> 
> If you run "telnet" from the Windows shell (cmd.exe), what happens?
> 
> Until you can successfully run telnet from Windows, there isn't any 
> point trying to run it from Python.
> 
> 
> --
> Steven
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python telnet

2011-11-19 Thread Rayon
Hi all got my code to work. 
I used an in queue and an out queue passed it to the telnet session . 
I am sending commands to the in_q  using sockets and passing them back data
with the out_q. 
Below is the code for a nonstop python telnet session. 
Thanks for the help, it got me thinking and that was worth it. 

def end_less():
"""
Start telnet session and never stop it :) 
"""
global host
global cmd_q
global out_q 
message = """
HLR DOWN ERROR
"""
try: 
hia_tel = telnetlib.Telnet(host)
hia_tel.set_debuglevel(1)
hia_tel.read_until("login:")
hia_tel.write('maint'+"\r")
hia_tel.read_until("Password:")
hia_tel.write("maint"+"\r")
hia_tel.read_until("maint@atcaHLRds0 /public/users/maint>")
while 1:
  try: 
command = cmd_q.get()
hia_tel.write(command+"\r")
data = hia_tel.read_until("maint@atcaHLRds0
/public/users/maint>")
out_q.put(data)
  except Exception,error:
error_email_mis(message)
logs('error',str(error),'null')
end_less()
time.sleep(10)
except Exception,error:
error_email_mis(message)
logs('error',str(error),'null') 

-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of Rayon
Sent: 19 November 2011 08:41
To: 'James Chapman'; tutor@python.org
Subject: Re: [Tutor] python telnet

Thanks but still not working, I am wondering if I need to give the script
some kind of special permission to execute on windows 7.

-Original Message-
From: tutor-bounces+evosweet=hotmail@python.org
[mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of James
Chapman
Sent: 19 November 2011 08:23
To: tutor@python.org
Subject: Re: [Tutor] python telnet

traceback has:
 child = winspawn('telnet 192.168.0.55:210')

When using telnet from CLI (on windows), you would type:
telnet 192.168.0.55 210

Note the space between the IP and port number and not a :colon.

Not sure this is your problem but probably worth mentioning.

--
James


At Saturday, 19/11/2011 on 11:44 Rayon wrote:
> I used the turn on turn off feature, and I can start a telnet session 
> from the command line.
> 
> -Original Message-
> From: tutor-bounces+evosweet=hotmail@python.org
> [mailto:tutor-bounces+evosweet=hotmail@python.org] On Behalf Of 
> Steven D'Aprano
> Sent: 19 November 2011 07:04
> To: tutor@python.org
> Subject: Re: [Tutor] python telnet
> 
> Rayon wrote:
> > I installed the telnet client but still the same error. 
> 
> How did you install it? Windows includes a telnet application, but it 
> has to be enabled first:
> 
> http://windows.microsoft.com/en-AU/windows-vista/Telnet-frequently-ask
> ed-que
> stions
> 
> If you run "telnet" from the Windows shell (cmd.exe), what happens?
> 
> Until you can successfully run telnet from Windows, there isn't any 
> point trying to run it from Python.
> 
> 
> --
> Steven
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor