[Tutor] Seeing response from authorization page with urllib2

2012-09-11 Thread Ray Jones
If I open a web page in my browser, I get a pop-up window that informs
me that I need to provide authorization information. But often, in
addition, that little pop-up window will give me some additional
information supplied by the page itself. For example, the chromium
browser pop-up might say, The server requires a username and password.
The server says: x

But when I attempt to get any part of an authorization-required page
using urllib2.urlopen(), I immediately receive the 401 error. Even the
intended object variable is left in an undefined state, so using info()
doesn't seem to work. How can I get that information from the server?


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


Re: [Tutor] simon says

2012-09-11 Thread Matthew Ngaha
 Sounds as though what is wanted in a Pythonic version of an early electronic 
 game Simon that was marketed back in the late 70's.  It was roughly Frisbee 
 shaped although slightly larger.  The top was divided into four 
 quadrant-shaped paddles each of a different color.  The game consisted of 
 Simon generating longer and longer sequences of random color-sound flashes 
 (each element in the sequence consisted of a momentary sound accompanied by 
 the appropriate quadrant lighting up).  After Simon had generated a sequence, 
 the player had to duplicate it by pressing the paddles.  A successful 
 recreation of a sequence was rewarded by Simon generating a longer one, until 
 the player finally screwed up.  At that point Simon made an electronic rude 
 noise and the device was handed on to the next player if there were multiple 
 players.  The player who succeeded in matching the longest sequence was the 
 winner of that round.

 I'll bet ebay still has them for sale, and Google would get you a description 
 that would be better than mine.

 -Bill

Thanks Bill. I did some more searching and managed to find a few new
versions on youtube with altered gameplay i guess. Here's the closest
to what has been described here:

http://www.youtube.com/watch?v=agUABjGAJww

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


Re: [Tutor] Seeing response from authorization page with urllib2

2012-09-11 Thread eryksun
On Tue, Sep 11, 2012 at 4:29 AM, Ray Jones crawlz...@gmail.com wrote:

 But when I attempt to get any part of an authorization-required page
 using urllib2.urlopen(), I immediately receive the 401 error. Even the
 intended object variable is left in an undefined state, so using info()
 doesn't seem to work. How can I get that information from the server?

The HTTPError object has the information you want: url, code, reason,
headers -- along with the methods info, read, readline, and readlines.

http://docs.python.org/library/urllib2#urllib2.HTTPError

For example, if you catch the error as e, then you can look at
e.headers['www-authenticate'] to find the realm.

Basic HTTP Authentication:
http://docs.python.org/library/urllib2#examples

You can also use an HTTPPasswordMgrWithDefaultRealm with a catch-all
realm (realm=None):

pass_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
auth_handler = urllib2.HTTPBasicAuthHandler(pass_mgr)
auth_handler.add_password(
realm=None,
uri='https://mahler:8092/site-updates.py',
user='klem',
passwd='kadidd!ehopper')
opener = urllib2.build_opener(auth_handler)

Optionally, install the opener:

urllib2.install_opener(opener)

Or just use opener.open().
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question

2012-09-11 Thread Ashley Fowler

I have a question. In a assignment it asks for me to do the following below...


if peek then print the Student object at the beginning
of the list (using __str__) but don't remove it from
the list;


Could you explain what it means?


This is what I have so far,

elif ask == peek:
print(First Name In List =, names[0])

How would you make it a string?


I know have a example of it but I'm not sure how to apply it to my code...The 
example is below.


def __str__(self):

return self.sides + \t + self.value



Also below is part of the assignment and my whole code is in the attachment.




A main function which does the following:
(1) create an empty list;
(2) ask the user if he/she wants to perform a list operation.
 if yes:
 (a) prompt the user for the operation:
test, peek, add, or remove;
 (b) perform the operation:
   (i) if test then print whether the list is empty or not;
   (ii) if peek then print the Student object at the beginning
of the list (using __str__) but don't remove it from
the list;
   (iii) if add, then prompt the user for student info, make
 a Student object containing that info, and
 add that Student object to the end of the list;
   (iv) if remove, then delete the Student object at the
beginning of the list and print it using __str__;
 repeat step (2) until the user enters no;
(3) neatly print the entire list from beginning to end.





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


[Tutor] Tkinter GUI

2012-09-11 Thread myles broomes

I'm coding a GUI program which presents the user with a resteraunt menu, and 
allows them to choose how much of each item they want to purchase before 
ordering. Here is my code: #Order up GUI program
#User is presented with a simple resturaunt menu
#They then select the items they want to order and then they are presented with 
the total billfrom tkinter import *class Application(Frame):
Based on the frame class, the application widget holds all other 
widgets. 
def __init__(self,master):
Initialise the frame. 
super(Application,self).__init__(master)
self.grid()
self.create_widgets()
self.total=0

self.spag_ent_check=True
self.tater_ent_check=True
self.soup_ent_check=True
self.fish_ent_check=Trueself.spag_cost=5.15
self.tater_cost=4.70
self.soup_cost=4.20
self.fish_cost=5.95def create_widgets(self):
Create all of the widgets in the program. 
Label(self,text=Select the items you want to 
order:).grid(row=0,column=0,sticky=W)
Label(self,text=Quantity:).grid(row=0,column=0,sticky=E)
Label(self,text=Spaghetti Bolognese (5.15)).grid(row=1,column=0,sticky=W)
self.spag_ent=Entry(self)
self.spag_ent.grid(row=1,column=0,sticky=E)
Label(self,text=Potato Salad (4.70)).grid(row=2,column=0,sticky=W)
self.tater_ent=Entry(self)
self.tater_ent.grid(row=2,column=0,sticky=E)
Label(self,text=Chicken Soup (4.20)).grid(row=3,column=0,sticky=W)
self.soup_ent=Entry(self)
self.soup_ent.grid(row=3,column=0,sticky=E)
Label(self,text=Smoked Salmon (5.95)).grid(row=4,column=0,sticky=W)
self.fish_ent=Entry(self)
self.fish_ent.grid(row=4,column=0,sticky=E)
Label(self,text=Total Bill:).grid(row=7,column=0,sticky=W)
self.bill_txt=Text(self,height=10,wrap=WORD)
self.bill_txt.grid(row=8,column=0,sticky=W)
Button(self,text=Order 
Up!,command=self.calc_total).grid(row=5,column=0,sticky=W)def 
calc_total(self):
Update the text widget if they order Spaghetti Bolognese. 
try:
int(spag_ent.get())
except:
message=You have to enter a number in the quantity box. \n
self.bill_txt.delete(0.0,END)
self.bill_txt.insert(0.0,message)
self.spag_ent_check=False # set to False if user enters anything 
other than an integer in the entry widgetif self.spag_ent_check:
spag_quant=self.spag_ent.get()
spag_total=self.spag_cost*spag_quant
self.total+=spag_totaltry:
int(tater_ent.get())
except:
message=You have to enter a number in the quantity box. \n
self.bill_txt.delete(0.0,END)
self.bill_txt.insert(0.0,message)
self.tater_ent_check=False # set to False if user enters anything 
other than an integer in the entry widgetif self.tater_ent_check:
tater_quant=self.tater_ent.get()
tater_total=self.tater_cost*tater_quant
self.total+=tater_totaltry:
int(soup_ent.get())
except:
message=You have to enter a number in the quantity box. \n
self.bill_txt.delete(0.0,END)
self.bill_txt.insert(0.0,message)
self.soup_ent_check=False # set to False if user enters anything 
other than an integer in the entry widgetif self.soup_ent_check:
soup_quant=self.soup_ent.get()
soup_total=self.soup_cost*soup_quant
self.total+=soup_totaltry:
int(fish_ent.get())
except:
message=You have to enter a number in the quantity box. \n
self.bill_txt.delete(0.0,END)
self.bill_txt.insert(0.0,message)
self.fish_ent_check=False # set to False if user enters anything 
other than an integer in the entry widgetif self.fish_ent_check:
fish_quant=self.fish_ent.get()
fish_total=self.fish_cost*fish_quant
self.total+=fish_total

self.bill_txt.delete(0.0,END)
self.bill_txt.insert(0.0,self.total)#main
root=Tk()
root.title(Order Up!)
app=Application(root)
root.mainloop()
The 'calc_total' function is supposed to calculate the users bill and then 
display it in the text widget, but every time I try it, it comes up as 0. Can 
anyone help me?  Thanks in advance,Myles Broomes
 ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter GUI

2012-09-11 Thread Albert-Jan Roskam
snip
    def calc_total(self):

    Update the text widget if they order Spaghetti Bolognese. 
    try:
    int(spag_ent.get())
    except:
    message=You have to enter a number in the quantity box. \n
snip
    
The 'calc_total' function is supposed to calculate the users bill and then 
display it in the text widget, but every time I try it, it comes up as 0. Can 
anyone help me? 
 
It struck me that you're not assigning int(spag_ent.get()) to any variable:
spaghettiAmount = int(spag_ent.get())
Moreover, I'd try to create the program in such a way that it doesn't become a 
headache to change the menu (for instance, to add a new pasta).
Perhaps by using a dctionary as a parameter: menu = {spaghetti: 4.50, 
macaroni: 2.10, calzone: 6.00}
Your example reminds me of one chapter of Head First Design Patterns 
(O'Reilly). Would be interesting to compare your approach with the one in the 
book.

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


Re: [Tutor] 'class' for someone with no object oriented programming experience

2012-09-11 Thread Brannon, Terrence


From: Tutor 
[mailto:tutor-bounces+terrence.brannon=bankofamerica@python.org] On Behalf 
Of Art Scheel
Sent: Tuesday, September 11, 2012 3:34 PM
To: tutor@python.org
Subject: [Tutor] 'class' for someone with no object oriented programming 
experience


Are there any better resources for learning classes for someone who's never 
touched object oriented programming in the past besides basic interpretation 
for debugging purposes?

[Terrence Brannon] Why don't you read this 
http://docs.python.org/tutorial/classes.html and write to this list regarding 
the first thing you don't understand.


--
This message w/attachments (message) is intended solely for the use of the 
intended recipient(s) and may contain information that is privileged, 
confidential or proprietary. If you are not an intended recipient, please 
notify the sender, and then please delete and destroy all copies and 
attachments, and be advised that any review or dissemination of, or the taking 
of any action in reliance on, the information contained in or attached to this 
message is prohibited. 
Unless specifically indicated, this message is not an offer to sell or a 
solicitation of any investment products or other financial product or service, 
an official confirmation of any transaction, or an official statement of 
Sender. Subject to applicable law, Sender may intercept, monitor, review and 
retain e-communications (EC) traveling through its networks/systems and may 
produce any such EC to regulators, law enforcement, in litigation and as 
required by law. 
The laws of the country of each sender/recipient may impact the handling of EC, 
and EC may be archived, supervised and produced in countries other than the 
country in which you are located. This message cannot be guaranteed to be 
secure or free of errors or viruses. 

References to Sender are references to any subsidiary of Bank of America 
Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are 
Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a 
Condition to Any Banking Service or Activity * Are Not Insured by Any Federal 
Government Agency. Attachments that are part of this EC may have additional 
important disclosures and disclaimers, which you should read. This message is 
subject to terms available at the following link: 
http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you 
consent to the foregoing.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question

2012-09-11 Thread Brannon, Terrence


From: Tutor 
[mailto:tutor-bounces+terrence.brannon=bankofamerica@python.org] On Behalf 
Of Ashley Fowler
Sent: Tuesday, September 11, 2012 12:08 PM
To: tutor@python.org
Subject: [Tutor] Question


I have a question. In a assignment it asks for me to do the following below...


if peek then print the Student object at the beginning

   of the list (using __str__) but don't remove it from

   the list;



Could you explain what it means?



This is what I have so far,

elif ask == peek:

print(First Name In List =, names[0])

How would you make it a string?

[Terrence Brannon] print(First name in List ={0}.format(names[0]))



--
This message w/attachments (message) is intended solely for the use of the 
intended recipient(s) and may contain information that is privileged, 
confidential or proprietary. If you are not an intended recipient, please 
notify the sender, and then please delete and destroy all copies and 
attachments, and be advised that any review or dissemination of, or the taking 
of any action in reliance on, the information contained in or attached to this 
message is prohibited. 
Unless specifically indicated, this message is not an offer to sell or a 
solicitation of any investment products or other financial product or service, 
an official confirmation of any transaction, or an official statement of 
Sender. Subject to applicable law, Sender may intercept, monitor, review and 
retain e-communications (EC) traveling through its networks/systems and may 
produce any such EC to regulators, law enforcement, in litigation and as 
required by law. 
The laws of the country of each sender/recipient may impact the handling of EC, 
and EC may be archived, supervised and produced in countries other than the 
country in which you are located. This message cannot be guaranteed to be 
secure or free of errors or viruses. 

References to Sender are references to any subsidiary of Bank of America 
Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are 
Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a 
Condition to Any Banking Service or Activity * Are Not Insured by Any Federal 
Government Agency. Attachments that are part of this EC may have additional 
important disclosures and disclaimers, which you should read. This message is 
subject to terms available at the following link: 
http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you 
consent to the foregoing.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question

2012-09-11 Thread eryksun
On Tue, Sep 11, 2012 at 12:08 PM, Ashley Fowler
afowl...@broncos.uncfsu.edu wrote:

 I have a question. In a assignment it asks for me to do the following
 below...

 if peek then print the Student object at the beginning
   of the list (using __str__) but don't remove it from
   the list;


 Could you explain what it means?

The __str__ special method of an object will be called when passed to
the built-in str() constructor. This method is required to return a
string.

For example, here's a class with an __str__ method that prints
calling __str__ to the screen in addition to returning the string
eggs. This demonstrates some of the ways __str__ is implicitly
called.


class Spam:
def __str__(self):
print(calling __str__)
return eggs


 s = Spam()

 str(s)
calling __str__
'eggs'

 spam and {}.format(s)
calling __str__
'spam and eggs'

 print(s)
calling __str__
eggs


Make sure __str__ returns a suitable string representation of the
student. The assignment should specify the string formatting of
Student objects.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked

2012-09-11 Thread ashish makani
Hi Python Tutor folks

I am stuck with an issue, so am coming to the Pythonistas who rescue me
everytime :)

I am trying to send out email programmatically, from a gmail a/c, using
smtplib, using the following chunk of code (b/w [  ] below)

[

import smtplib
from email.mime.text import MIMEText

#uname, pwd are username  password of gmail a/c i am trying to send from

server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls() # get response(220, '2.0.0 Ready to start TLS')
server.login(uname,pwd)  # get response(235, '2.7.0 Accepted')

toaddrs  = ['x...@gmail.com', 'y...@gmail.com' ] # list of To email addresses
msg = MIMEText('email body')
msg['Subject'] = 'email subject'
server.sendmail(fromaddr, toaddrs, msg.as_string())


]

The code above works perfectly fine on my local machine, but fails on the
production server at the university where i work( all ports other than port
80 are blocked) :(

So , when i try to run the 2 py statements (in bold below) on a python
prompt from the production server, which has port 587 blocked, i get the
following error

{
* import smtplib*
* server = smtplib.SMTP('smtp.gmail.com:587')*
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python2.6/smtplib.py, line 239, in __init__
(code, msg) = self.connect(host, port)
  File /usr/lib/python2.6/smtplib.py, line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
  File /usr/lib/python2.6/smtplib.py, line 273, in _get_socket
return socket.create_connection((port, host), timeout)
  File /usr/lib/python2.6/socket.py, line 514, in create_connection
raise error, msg
socket.error: [Errno 101] Network is unreachable

}


1. How can i overcome this ?
A friend suggested , that i could use something called smtp relay, which
would solve my problem, but would be time-consuming  a pain to set up.
I did some cursory googling  searching on stackoverflow but could not find
any good, well explained results.
I dont know anything about SMTP.
Anybody has any recommendations on a good explanation on smtp relay  how
to set it up for sending email from a gmail a/c using a python script ?

2. Also, is there a more elegant/cleaner/graceful solution to my problem
than using an smtp relay ?

Any  all explanations/links/code
snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor
community would be greatly appreciated.

Thanks a ton

cheers
ashish

email :
ashish.makani
domain:gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked

2012-09-11 Thread Emile van Sebille

On 9/11/2012 2:19 PM ashish makani said...

Hi Python Tutor folks

I am stuck with an issue, so am coming to the Pythonistas who rescue me
everytime :)

I am trying to send out email programmatically, from a gmail a/c, using
smtplib, using the following chunk of code (b/w [  ] below)

[

import smtplib
from email.mime.text import MIMEText

#uname, pwd are username  password of gmail a/c i am trying to send from

server = smtplib.SMTP('smtp.gmail.com:587 http://smtp.gmail.com:587/')
server.starttls() # get response(220, '2.0.0 Ready to start TLS')
server.login(uname,pwd)  # get response(235, '2.7.0 Accepted')

toaddrs  = ['x...@gmail.com mailto:x...@gmail.com', 'y...@gmail.com
mailto:y...@gmail.com' ] # list of To email addresses
msg = MIMEText('email body')
msg['Subject'] = 'email subject'
server.sendmail(fromaddr, toaddrs, msg.as_string())


]

The code above works perfectly fine on my local machine, but fails on
the production server at the university where i work( all ports other
than port 80 are blocked) :(


Good -- the university is taking steps to block spam.

You should send mail using the university mail system and not 
smtp.gmail.com.


Emile


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


Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked

2012-09-11 Thread ashish makani
Folks,

some more context so people presume we are spammers :)

These emails are automated diagnostic emails sent to a group of a few
admins, so we get notified when a python heartbeat script, detects a
failure in things like n/w connectivity, router status, etc.
We dont use university email, we use gmail.

Emile,
Please don't presume people's intentions (that we are sending spam)  judge
people without knowing anything about them.
We are a tiny startup trying to connect rural communities using voice  ivr
systems - http://gramvaani.org/

Best,
ashish


On Wed, Sep 12, 2012 at 2:56 AM, Emile van Sebille em...@fenx.com wrote:

 On 9/11/2012 2:19 PM ashish makani said...

 Hi Python Tutor folks

 I am stuck with an issue, so am coming to the Pythonistas who rescue me
 everytime :)

 I am trying to send out email programmatically, from a gmail a/c, using
 smtplib, using the following chunk of code (b/w [  ] below)

 [

 import smtplib
 from email.mime.text import MIMEText

 #uname, pwd are username  password of gmail a/c i am trying to send from

 server = smtplib.SMTP('smtp.gmail.com:**587 http://smtp.gmail.com:587 
 http://smtp.gmail.com:587/')

 server.starttls() # get response(220, '2.0.0 Ready to start TLS')
 server.login(uname,pwd)  # get response(235, '2.7.0 Accepted')

 toaddrs  = ['x...@gmail.com mailto:x...@gmail.com', 'y...@gmail.com
 mailto:y...@gmail.com' ] # list of To email addresses

 msg = MIMEText('email body')
 msg['Subject'] = 'email subject'
 server.sendmail(fromaddr, toaddrs, msg.as_string())


 ]

 The code above works perfectly fine on my local machine, but fails on
 the production server at the university where i work( all ports other
 than port 80 are blocked) :(


 Good -- the university is taking steps to block spam.

 You should send mail using the university mail system and not
 smtp.gmail.com.

 Emile


 __**_
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/**mailman/listinfo/tutorhttp://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] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked

2012-09-11 Thread Walter Prins
Hi Ashish,

On 11 September 2012 22:44, ashish makani ashish.mak...@gmail.com wrote:
 These emails are automated diagnostic emails sent to a group of a few
 admins, so we get notified when a python heartbeat script, detects a failure
 in things like n/w connectivity, router status, etc.
 We dont use university email, we use gmail.

 Emile,
 Please don't presume people's intentions (that we are sending spam)  judge
 people without knowing anything about them.
 We are a tiny startup trying to connect rural communities using voice  ivr
 systems - http://gramvaani.org/

OK, well I'm sure you can see how an apparent newbie asking to get out
of a university network without any explanation can be seem um,
suspect, so I think Emile's response was reasonable.   I must further
note that I can't actually see how/where your request actually fits
under the projects listed by that site.  So, colour me still a bit
sceptical, but I'll give you the benefit of the doubt.

So then, given that you can only get out on port 80, your only real
option the way I see it is to write a small web service, maybe a SOAP
or preferably ReST service, to run on e.g. Google APP engine that will
do the emailing for you.Of course, you'll have to consider whether
to implement some security yourself if you use port 80 as the data
going over the wire will be sent unencrypted.  It may not be a problem
but then again it may.  Note, alternatively you can perhaps also use
https (port 443), if that's also open as that will give you end-to-end
encryption for free. (But I have no idea and suspect that this may
also introduce a boatload of other complications...)

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


Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked

2012-09-11 Thread Marc Tompkins
On Tue, Sep 11, 2012 at 2:44 PM, ashish makani ashish.mak...@gmail.comwrote:

 Folks,

 some more context so people presume we are spammers :)

 These emails are automated diagnostic emails sent to a group of a few
 admins, so we get notified when a python heartbeat script, detects a
 failure in things like n/w connectivity, router status, etc.
 We dont use university email, we use gmail.

 Emile,
 Please don't presume people's intentions (that we are sending spam) 
 judge people without knowing anything about them.
 We are a tiny startup trying to connect rural communities using voice 
 ivr systems - http://gramvaani.org/


I think you might have been presuming Emile's intention too...

Blocking port 587 is a standard, prudent, and correct action for the
university (ANY network that allows guest access, actually) to take to help
prevent spam.  The problem is that you (and I do, truly, presume that your
intentions are honorable) would not be the only person/system that could
use port 587 if it were unblocked.  Sure, we trust YOU - but what about
everybody else?

So there are several ways to go about this:
  -  the standard way, which would be to use the university's SMTP server -
which can require a username/password before sending; not perfect but
better than nothing
  -  you can work with the university's network admin to grant you or your
app an exception to the firewall rule - IF their firewall, and their
policies, allow such an exception
  -  you could establish a VPN tunnel to some server outside of the
university's network and send from port 587 on THAT machine.  Complicated,
weird, and not horribly secure.  But doable.




 Best,
 ashish


 On Wed, Sep 12, 2012 at 2:56 AM, Emile van Sebille em...@fenx.com wrote:

 On 9/11/2012 2:19 PM ashish makani said...

 Hi Python Tutor folks

 I am stuck with an issue, so am coming to the Pythonistas who rescue me
 everytime :)

 I am trying to send out email programmatically, from a gmail a/c, using
 smtplib, using the following chunk of code (b/w [  ] below)

 [

 import smtplib
 from email.mime.text import MIMEText

 #uname, pwd are username  password of gmail a/c i am trying to send from

 server = smtplib.SMTP('smtp.gmail.com:**587 http://smtp.gmail.com:587
 http://smtp.gmail.com:587/')

 server.starttls() # get response(220, '2.0.0 Ready to start TLS')
 server.login(uname,pwd)  # get response(235, '2.7.0 Accepted')

 toaddrs  = ['x...@gmail.com mailto:x...@gmail.com', 'y...@gmail.com
 mailto:y...@gmail.com' ] # list of To email addresses

 msg = MIMEText('email body')
 msg['Subject'] = 'email subject'
 server.sendmail(fromaddr, toaddrs, msg.as_string())


 ]

 The code above works perfectly fine on my local machine, but fails on
 the production server at the university where i work( all ports other
 than port 80 are blocked) :(


 Good -- the university is taking steps to block spam.

 You should send mail using the university mail system and not
 smtp.gmail.com.

 Emile


 __**_
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/**mailman/listinfo/tutorhttp://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] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked

2012-09-11 Thread ashish makani
Walter, Marc,

Thanks for your helpful suggestions  super quick replies.

As a noobie, i often run into brick walls, thinking something(problem i am
stuck at) is not possible to do in python.
I love struggling against that problem  figuring a way out.

I have posted to the tutor mailing list in the past  the community here
has always been amazingly welcoming  super helpful, so as a n00b, i was
just a little taken aback surprised at Emil's not particularly helpful ,
yet completely accurate response :)

Marc,
your 3rd point,

 you could establish a VPN tunnel to some server outside of the
 university's network and send from port 587 on THAT machine.  Complicated,
 weird, and not horribly secure.  But doable.

Could you point me to a good link/resource on how to do this ?

Walter,
you suggested writing a web service running somewhere else (e.g. Google
Apps, AWS, etc) which i could request from my python code, which in turn
would do the emailing.
Can you point me to any good links/example code which might explain writing
a simple SOAP/ReST web service using port80(http) or preferably,
 443(https).
I know nothing about web services, but could this web service essentially
be the python email code, i mentioned in my original post, if i run it on
Google App Engine ?

Thanks a ton,

Best,
ashish

On Wed, Sep 12, 2012 at 3:29 AM, Walter Prins wpr...@gmail.com wrote:

 Hi Ashish,

 On 11 September 2012 22:44, ashish makani ashish.mak...@gmail.com wrote:
  These emails are automated diagnostic emails sent to a group of a few
  admins, so we get notified when a python heartbeat script, detects a
 failure
  in things like n/w connectivity, router status, etc.
  We dont use university email, we use gmail.
 
  Emile,
  Please don't presume people's intentions (that we are sending spam) 
 judge
  people without knowing anything about them.
  We are a tiny startup trying to connect rural communities using voice 
 ivr
  systems - http://gramvaani.org/

 OK, well I'm sure you can see how an apparent newbie asking to get out
 of a university network without any explanation can be seem um,
 suspect, so I think Emile's response was reasonable.   I must further
 note that I can't actually see how/where your request actually fits
 under the projects listed by that site.  So, colour me still a bit
 sceptical, but I'll give you the benefit of the doubt.

 So then, given that you can only get out on port 80, your only real
 option the way I see it is to write a small web service, maybe a SOAP
 or preferably ReST service, to run on e.g. Google APP engine that will
 do the emailing for you.Of course, you'll have to consider whether
 to implement some security yourself if you use port 80 as the data
 going over the wire will be sent unencrypted.  It may not be a problem
 but then again it may.  Note, alternatively you can perhaps also use
 https (port 443), if that's also open as that will give you end-to-end
 encryption for free. (But I have no idea and suspect that this may
 also introduce a boatload of other complications...)

 Walter
 ___
 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] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked

2012-09-11 Thread Emile van Sebille

On 9/11/2012 2:44 PM ashish makani said...

Emile,
Please don't presume people's intentions (that we are sending spam) 
judge people without knowing anything about them.


I made no such presumption -- I appluad the university for taking 
appropriate actions to reduce the spread of spam.  Perhaps you're not 
familiar with spam botnets.  See http://en.wikipedia.org/wiki/Botnet


Emile

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


Re: [Tutor] Python in Vertica

2012-09-11 Thread Dave Angel
A couple of points of order:  please do a reply-all, or equivalent, so
your response goes to the forum, and not just to one person.  or you can
add tutor@python.org to it, if that seem easier.

Also, please don't top-post on the forum, unless you're deleting all
context.  And you usually shouldn't delete all of it, just the parts
that aren't relevant.

On 09/11/2012 09:18 AM, C.L. Shetline wrote:
 If you're claiming that's coming from the above print statement (after
 fixing the syntax error), then the variable number_of_rows is NOT a long
 or an int.  Perhaps it's a string.  Without knowing that, we can't tell
 you the best way to fix it.
 
 Yes, it is coming from the print (claiming? Would I lie about that?). And no, 
 there was not a syntax error, it was a

Not lie, but you might have been mistaken.  Now that I see all the code,
I know you were not mistaken.

 cut and paste error.

Since only part of the line was included, it gives a syntax error. Now
that I see the whole line, I realize what happened.  See below.

 
 This is the entire small test script:
 
 #!/usr/bin/python
 
 import pyodbc
 import time
 import os
 import sys
 
 
 cnstr = DSN=dwprod;PWD=S@1b@b@18;Charset=UTF-8
 targetSchema = 'public'
 
 cnxn = pyodbc.connect(cnstr, autocommit=False)
 cursor = cnxn.cursor()
 
 
 cursor.execute(SELECT COUNT(*) from cv_gls_wkly_misc)
 result = cursor.fetchone()
 number_of_rows = result[0]
 print `number_of_rows`

Here you're using a deprecated form of syntax.  The backquotes mean to
call repr() on the object inside.  The repr() function tries to give you
enough characters that you could reproduce the object.

Just remove the backquotes, and you won't see the trailing L.

print number_of_rows

 
 cursor.execute('SELECT * FROM cv_gls_wkly_misc where period_gen_key = 5185')
 print cursor.fetchall()
 
 
 cursor.close()
 cnxn.close()
 
 It is executed from the command line:
 
 vertica1:dbadmin:/pro/COLEGIFT/source/fix/cece/sistest ./sisupd1.py
 4L
 [(5185L, 93L, Decimal(42.50), Decimal(50.36), Decimal(3406.35), 
 Decimal(0), Decimal(78.00), Decimal(0), Decimal(66.00), Decimal(0), 
 Decimal(12.73), Decimal(0), Decimal(0), Decimal(311.00))]
 
 I do not know why it is printing a data type along with the value. I do not 
 know if this is a Python issue or a Vertica issue.
 
 Regards,
 CVez
 

-- 

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


Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked

2012-09-11 Thread Marc Tompkins
On Tue, Sep 11, 2012 at 3:27 PM, ashish makani ashish.mak...@gmail.comwrote:

 Marc,
 your 3rd point,

 you could establish a VPN tunnel to some server outside of the
 university's network and send from port 587 on THAT machine.  Complicated,
 weird, and not horribly secure.  But doable.

 Could you point me to a good link/resource on how to do this ?


Hmmm... having said that, I'm puzzling over the simplest way to actually do
it.  First idea (based on stuff I've set up in the past):
-  at your outside location, set up a VPN endpoint/router, with your SMTP
server sitting behind it
-  on your computer inside the university's network, install a VPN client
and establish the tunnel before launching your script

I am very fond of pfSense http://www.pfsense.org as a router/firewall; it
has OpenVPN http://openvpn.net/index.php/open-source.html support baked
in, and if you install the OpenVPN Client Export Utility package (a
single click, once pfSense is installed) it will export a ready-made
configuration file for the remote machine.

Two things:
-  as I said, this is a complicated and weird way to do this, although it's
probably more secure than I thought when I first mentioned it.  But it's
probably NOT the best way to go about it.
-  somebody out there, with better Python chops than I, will no doubt point
out a way to do the same thing all in Python.  Even if this were the proper
approach, I'm not guaranteeing it's the best way to implement it.

If you do decide to go this way, you'll need a machine (it could even be a
virtual machine, but I find it much simpler to use an old junker PC with
two network cards) to run pfSense, and of course an SMTP server.
I'd just like to add a quick endorsement for pfSense in general, by the way
- it's free and open-source, but I have yet to find anything it doesn't do,
and do well, compared to Cisco/Juniper/SonicWall/etc.  Of course, the old
junker PC you run it on needs to be in decent working condition - stable
power supply (and power!), no flaky memory or unstable NICs - but it
doesn't need to be very new or very powerful.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Constructing a object

2012-09-11 Thread Ashley Fowler
How do you construct a object using variables?

For instance I have to construct a student object, by first prompting the user 
to enter variables for the Student class (their first and last names, credits 
and gpa) then construct a Student object using those variables.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Constructing a object

2012-09-11 Thread Dwight Hutto
On Tue, Sep 11, 2012 at 10:23 PM, Ashley Fowler afowl...@broncos.uncfsu.edu
 wrote:

  How do you construct a object using variables?

  For instance I have to construct a student object, by first prompting
 the user to enter variables for the Student class (their first and last
 names, credits and gpa) then construct a Student object using those
 variables.




   First you want to collect the variables from the user, like so:

 student_first_name = raw_input(Enter First Name: )
Enter First Name: David


Then I would init the class with these variable, and return a tuple, or
dict.

If I'm getting the question you're asking correctly. Except I'd just use a
function to call(instead of a class, but this might be the assignment given
to you), and collect it there, then write the data to a db, or a custom db
file.


Or you could call the class without init, then go through the input in
different functions by defining them as self.first_name = raw_input(Enter
First Name: ), collect those into a return value, and pass them through
another function/class that inserted the data into a db.
-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked

2012-09-11 Thread Dwight Hutto
Why don't you ask the university to setup a password protection on port 587
to allow access to specific users, and then they can monitor the
incoming/outgoing connections identified by the user name?

As well as encryption known by the university to monitor activity on other
levels.


-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Constructing a object

2012-09-11 Thread eryksun
On Tue, Sep 11, 2012 at 10:23 PM, Ashley Fowler
afowl...@broncos.uncfsu.edu wrote:
 How do you construct a object using variables?

 For instance I have to construct a student object, by first prompting the
 user to enter variables for the Student class (their first and last names,
 credits and gpa) then construct a Student object using those variables.

You need to write a function that gets user input and converts it
where appropriate (e.g. int, float).


def make_student_from_input():

# input and convert
first_name = ...
last_name = ...
num_credits = ...
gpa = ...

return Student(first_name, last_name, num_credits, gpa)


This assumes the Student initializer (__init__) is as follows:


class Student(object):

def __init__(self, first_name, last_name, num_credits, gpa):
# ...


The constructor supplies the 'self' argument in position 0. The rest,
if supplied as positional arguments, need to be provided in exactly
the same order as the argument list. The names do not matter. Whatever
argument is in position 1 will be assigned to the local variable
'first_name'. Whatever argument is in position 4 will be assigned to
the local variable 'gpa'.

On the other hand, if you supply each argument name as a keyword,
you're free to list them in any order. For example:

first_name, last_name = 'John', 'Doe'
num_credits, gpa = 60, 3.5

student = Student(
gpa=gpa,
num_credits=num_credits,
last_name=last_name,
first_name=first_name)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Musical note on python

2012-09-11 Thread D . V . N . Sarma డి . వి . ఎన్ . శర్మ
How to produce  a musical note of given frequency,volume and duration in
Python.


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