473,222 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,222 software developers and data experts.

email module, redirecting to stdout


Hello,

I have this code:

s = smtplib.SMTP()
s.set_debuglevel(1)
s.connect(host=smtp_host)
s.set_debuglevel(0)
log("Connected, sending e-mail")
sys.stdout.flush()
s.sendmail(
consts.EMAIL_FROMADDRESS,
[to],
msg.as_string()
)
log("E-mail sent OK")
s.quit()

The problem is that whenever I set the debuglevel to 1, messages will go
to stderr. I would like them to go to stdout. Using

sys.stderr = sys.stdout

has no effect. Redirecting stderr to stdout from the shell is not an
option for me, because I need to use stderr for other messages.

Thanks,

Les

Oct 4 '05 #1
3 3387
Laszlo Zsolt Nagy wrote:
I have this code:

s = smtplib.SMTP()
s.set_debuglevel(1)
s.connect(host=smtp_host)
s.set_debuglevel(0)
log("Connected, sending e-mail")
sys.stdout.flush()
s.sendmail(
consts.EMAIL_FROMADDRESS,
[to],
msg.as_string()
)
log("E-mail sent OK")
s.quit()

The problem is that whenever I set the debuglevel to 1, messages will go
to stderr. I would like them to go to stdout. Using

sys.stderr = sys.stdout

has no effect. Redirecting stderr to stdout from the shell is not an
option for me, because I need to use stderr for other messages.


smtplib obtains a copy of stderr by

from sys import stderr

Therefore you have to do

smtplib.stderr = sys.stdout

to get the desired effect.

Peter


Oct 4 '05 #2
In article <dh*************@news.t-online.com>,
Peter Otten <__*******@web.de> wrote:
Laszlo Zsolt Nagy wrote:
I have this code:

s = smtplib.SMTP()
s.set_debuglevel(1)
s.connect(host=smtp_host)
s.set_debuglevel(0)
log("Connected, sending e-mail")
sys.stdout.flush()
s.sendmail(
consts.EMAIL_FROMADDRESS,
[to],
msg.as_string()
)
log("E-mail sent OK")
s.quit()

The problem is that whenever I set the debuglevel to 1, messages will go
to stderr. I would like them to go to stdout. Using

sys.stderr = sys.stdout

has no effect. Redirecting stderr to stdout from the shell is not an
option for me, because I need to use stderr for other messages.


smtplib obtains a copy of stderr by

from sys import stderr

Therefore you have to do

smtplib.stderr = sys.stdout

to get the desired effect.


Ouch. I'd consider this a bug. "from sys import stderr" should at least
be considered bad style.

Just
Oct 4 '05 #3
Just wrote:
smtplib obtains a copy of stderr by
from sys import stderr
Ouch. I'd consider this a bug. "from sys import stderr" should at least
be considered bad style.


I'd rather say this is the low-tech equivalent to

debug = logging.getLogger("smtplib").debug

an approach which is currently only taken by the cookielib module.

Peter

Oct 4 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Birch | last post by:
I have a python script that uses the print function throughout, and as well uses calls to os.system() to spawn DOS commandline executables. My issue is that I redirect all of the output from this...
1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
3
by: legba | last post by:
hi all.. I'm writing an application in python2.3 under linux debian which accepts new "plug-ins" in the form of c-written python extension modules. My problem is that I'd like to catch the...
3
by: David Douard | last post by:
Hi everybody, let me explain by problem: I am working on an application which consists in a C++ dll (numeric computations) and a Python IHM (Python/Tk), which must run under Linux and win32. My...
15
by: Matt Burland | last post by:
I'm having a problem with redirecting the StandardOutput of a process that I use to run a DOS program in my application. The problem is that I when I start my process (which I do in a separate...
1
by: pp4175 | last post by:
Hello Everyone, I am currently working on writing a GUI wrapper for a Menu driven DOS Program. What I was looking on doing is redirecting stdout/stdin to a stream and read/write similar to a...
5
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
I wanna print the log to both the screen and file, so I simulatered a 'tee' class Tee(file): def __init__(self, name, mode): file.__init__(self, name, mode) self.stdout = sys.stdout...
4
by: ElderGeek | last post by:
Hi, all. I am coding in C on Linux, and using an external library provided by others. This library generates a batch of error/warning messages to stdout, which I do not want to see. Before...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.