RotatingFileHandler Error
Hi
I am trying to use RotatingFileHandler, in the foll way :
rootLogger = logging.getLogger('')
rootLogger.setLevel(logging.DEBUG)
rotatingHandler =
logging.handlers.RotatingFileHandler(self.logobj_path.name,"a", 1000,
10)
rotatingHandler.doRollover()
rotatingHandler.emit()
rootLogger.addHandler(rotatingHandler)
logging.info('info')
self.logger = logging.getLogger('myapp.area1')
It results in the foll error :
lne 86, in __init__
rotatingHandler.doRollover()
File "c:\python24\lib\logging\handlers.py", line 131, in doRollover
os.rename(self.baseFilename, dfn)
OSError: [Errno 13] Permission denied
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "c:\python24\lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "c:\python24\lib\logging\__init__.py", line 1351, in shutdown
h.flush()
File "c:\python24\lib\logging\__init__.py", line 731, in flush
self.stream.flush()
ValueError: I/O operation on closed file
Error in sys.exitfunc:
Traceback (most recent call last):
File "c:\python24\lib\atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "c:\python24\lib\logging\__init__.py", line 1351, in shutdown
h.flush()
File "c:\python24\lib\logging\__init__.py", line 731, in flush
self.stream.flush()
ValueError: I/O operation on closed file
Can anyone tell me, w hat is wrong with my code.
Roopesh
--
http://mail.python.org/mailman/listinfo/python-list
Mod python - mysql lock
Hi, In my mod_python project I am using mysql as the database. There is table card in which unique cards are stored. When a user request comes he has to get a unique card. In this situation I want to use LOCK with which I can prevent other users accessing the table. I tried excuting "LOCK" command of mysql through python code, but it is not locking the database. Any ideas why this isn't working and how can I do the same. //python code sql = "LOCK TABLES card WRITE" cursor.execute(sql) Regards Roopesh -- http://mail.python.org/mailman/listinfo/python-list
sslerror: (8, 'EOF occurred in violation of protocol')
I am getting an SSL error while fetching mails from Gmail over SSL on
Port 995. This problem occurs occasionally only, otherwise it works
file. Any idea why it happens.
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\python24\lib\threading.py", line 442, in __bootstrap
self.run()
File
"C:\The_email_archive_system\email_archiver\pensive\mail_source.py",
line
425, in run
self.download_mails ()
File
"C:\The_email_archive_system\email_archiver\pensive\mail_source.py",
line
403, in download_mails
mymsg = M.retr(msg_no)
File "c:\python24\lib\poplib.py", line 237, in retr
return self._longcmd('RETR %s' % which)
File "c:\python24\lib\poplib.py", line 172, in _longcmd
return self._getlongresp()
File "c:\python24\lib\poplib.py", line 157, in _getlongresp
line, o = self._getline()
File "c:\python24\lib\poplib.py", line 374, in _getline
self._fillBuffer()
File "c:\python24\lib\poplib.py", line 364, in _fillBuffer
localbuf = self.sslobj.read()
sslerror: (8, 'EOF occurred in violation of protocol')
Regards
Roopesh
--
http://mail.python.org/mailman/listinfo/python-list
IMAP SEARCH Error
I am using the imaplib to fetch mails. There is an error thrown in the
search function, which I am not able to comprehend.
My program is as follows :
import imaplib
M = imaplib.IMAP4("10.1.1.1",1143)
M.login("roopesh", "roopesh12")
type, data = M.select("INBOX", 1)
print type, data
print M.status("INBOX", '(MESSAGES UNSEEN RECENT)')
typ, data = M.search(None, '(ALL)')
print typ, data
for num in data[0].split():
typ, data = M.fetch(num, '(RFC822)')
print 'Message %s\n%s\n' % (num, data[0][1])
M.close()
M.logout()
And the OUTPUT in the console is as follows :
==
OK ['24']
('OK', ['INBOX ( MESSAGES 24 UNSEEN 0 RECENT 0)'])
Traceback (most recent call last):
File "imap_test1.py", line 10, in ?
typ, data = M.search(None, '(ALL)')
File "c:\python24\lib\imaplib.py", line 602, in search
typ, dat = self._simple_command(name, *criteria)
File "c:\python24\lib\imaplib.py", line 1028, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "c:\python24\lib\imaplib.py", line 860, in _command_complete
raise self.abort('command: %s => %s' % (name, val))
imaplib.abort: command: SEARCH => unexpected response: '*'
Can anyone tell me why this happens ?
Regards
Roopesh
--
http://mail.python.org/mailman/listinfo/python-list
cPickle EOF Error
I am trying to write xml files which are inside a zip file into the
database.
In the zipfile module the function read returns bytes. What I did was
to make a blob out of the returned bytes and write it to the
database(for this I used cPickle). I also used _mysql's escape_string
which escapes some characters (without this the file content was not
getting written). But once we try to unpickle the content, an EOF
error is getting thrown. When I tried putting the content(xml in
database) to a file without unpickling then the xml file with escape
characters gets printed.
My code is as follows :
def import_cards():
try :
conn =
MySQLdb.connect(host="localhost",port=3306,user="roopesh",passwd="pass",db="mydbs")
cursor = conn.cursor()
cursor.execute("CREATE TABLE card (serial_no int(10),
id varchar(50), data blob, used char(1), ip varchar(20),
date_downloaded datetime)")
z = zipfile.ZipFile('/home/roopesh/public_html/
cards.zip', 'r')
sql = "INSERT INTO card (serial_no, id, data, used)
values (%s, %s, %s, %s)"
for filename in z.namelist() :
bytes = z.read(filename)
data = cPickle.dumps(bytes, 2)
#print data
cursor.execute(sql, (1, filename ,
_mysql.escape_string(data), 'n'))
sql = "SELECT serial_no, id, data, used FROM card"
cursor.execute(sql)
for serial_no, id, data, used in cursor.fetchall() :
print serial_no, id,
cPickle.loads(data.tostring())
#f = open(id ,'wb')
#f.write(data.tostring())
finally :
cursor.execute("DROP TABLE card")
conn.close()
return True
The output is :
[EMAIL PROTECTED]:~/public_html$ python cardManagement.py
1 cards/passcard1.xml
Traceback (most recent call last):
File "cardManagement.py", line 136, in ?
import_cards()
File "cardManagement.py", line 28, in import_cards
print serial_no, id, cPickle.loads(data.tostring())
EOFError
--
http://mail.python.org/mailman/listinfo/python-list
ConfigObj quoting issues
Hi,
I am using ConfigObj to write email addresses, as a list. I am using
email module functions to extract email addresses:
to_address = header.get_all('To', [])
address_list = getaddresses(to_address)
to = map(lambda address: '"'+address[0]+'"
<'+address[1]+'>' ,address_list)
conf_obj['to'] = to
But quite often I am getting the error "cannot be safely quoted.".
This error is because of the presence of \', \", \n etc.
I had to do the following to make it work.
address[i].replace("\'",'').replace('\"','').replace('\n','')
[making list_all=False doesn't work properly(it fails when the first
character is a double quote). ]
I don't want to do the above, as it modifies the email address (name).
In brief, my question is how to save a list of strings which might
have quotes, double quotes to a file using ConfigObj.
Any idea what is to be done.
Thanks
Roopesh
--
http://mail.python.org/mailman/listinfo/python-list
poplib - retr() getting stuck
Hi, I am using poplib's retr() to fetch mails from my gmail account. It works fine, in some cases it gets stuck inside the retr() method and does not come out. >From the logs I could find that when retr() is called, it stops executing further statements, nor does it throw an exceptions but simply stops. My code is roughly like the foll: try: print "1" mymsg = M.retr(msg_no) print "2" except poplib.error_proto, e: print "exception1" except Exception, e: print "exception2" What can be the reason for this? Can anyone help me. Thanks Roopesh -- http://mail.python.org/mailman/listinfo/python-list
POP3_SSL Error
Hi, While using poplib to fetch mails from my gmail account, I am getting the following error: Exception is POP3_SSL instance has no attribute 'sslobj' Can anyone tell me what this error means. Thanks and Regards Roopesh -- http://mail.python.org/mailman/listinfo/python-list
Problems with file IO in a thread, and shutil
Hi,
I have a multithreaded application. There are two threads, T1 and T2.
Suppose that there are two folders A, B. Thread T1 fetches data from
network and creates files in folder A and after creating each file, it
moves the file to folder B, using shutil.move().
Thread T2, takes files from folder B and processes it.
Note: Only the thread T1 has access to the files in folder A.
psuedo code
=
class T1(thread):
def run():
self.download()
def download():
data = from_network
filename = os.path.join ( "A", "file1")
f = open ( filename, "w")
for d in data:
f.write ( d + "\n" )
f.flush()
f.close()
shutil.move(os.path.join ( "A", "file1"), os.path.join("B",
"file1"))
class T2(thread):
run()
process(listdir(os.path.join("B")))
All the files has similar contents. But in some cases(very rare), when
thread T1 tries to move the newly created file from folder A to folder
B, an exception occurs (on shutil.move()).
The exception is WindowsError(32, 'The process cannot access the file
because it is being used by another process'). I looked inside the
shutil.move. What I found was due to this WindowsError, the usual
os.rename() inside shutil.move() fails and the file is copied using
copy2(src, dst). Finally os.unlink() also failed. (So though copying
occurred, deleting the source file failed)
I am not getting why this error comes. Has anyone faced similar
situation? Please help me.
Thanks and Regards
Roopesh
--
http://mail.python.org/mailman/listinfo/python-list
Re: recursion in Class-methods?
Wrong: newpath = find_path(self.dictionary, node, end, path) newpaths = find_all_paths(self.dictionary, node, end, path) newpath = find_shortest_path(self.dictionary, node, end, path) Correct; newpath = self.find_path(self.dictionary, node, end, path) newpaths = self.find_all_paths(self.dictionary, node, end, path) newpath = self.find_shortest_path(self.dictionary, node, end, path) Regards Roopesh -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with file IO in a thread, and shutil
Thanks for the reply. I did testing in a clean system, were anti virus/ spyware is not installed. It still gave this problem, in say 1 out of 1000 cases. By any chance would it be possible that the Windows OS has not completed writing to the file even after file.flush() and file.close() is called? Thanks Roopesh -- http://mail.python.org/mailman/listinfo/python-list
Re: poplib - retr() getting stuck
Thanks for the help. At present I have modified the poplib code as follows (In POP3 and POP3_SSL classes): Is it the correct way? def __init__(self, host, port = POP3_PORT): self.host = host self.port = port msg = "getaddrinfo returns an empty list" self.sock = None socket.setdefaulttimeout(30) for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): af, socktype, proto, canonname, sa = res try: self.sock = socket.socket(af, socktype, proto) self.sock.connect(sa) except socket.error, msg: Thanks Roopesh -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems with file IO in a thread, and shutil
> Maybe it's a Windows service, eg the indexing service or generating > thumbnails. Anyway, retrying after a delay would still be worth it. Yes, this thing works :-) Thanks a lot. Thanks Roopesh -- http://mail.python.org/mailman/listinfo/python-list
Bug in email.utils, parseaddr
Hi,
I tried using parseaddr of email.utils, but it gave the following
result when the name had a comma inside.
>>> e = 'K,Vishal <[EMAIL PROTECTED]>'
>>> from email.utils import parseaddr
>>> parseaddr(e)
('', 'K')
Thanks and Regards,
Roopesh
--
http://mail.python.org/mailman/listinfo/python-list
How to make xss safe strings
Hi,
How can I make a string XSS safe? Will
simply .replace('<','<').replace('>','>') do the work? Or
are there some other issues to take into account?. Is there already a
function in python which will do this for me.
Regards
Roopesh
--
http://mail.python.org/mailman/listinfo/python-list
