>You're trying to connect to the same port on >localhost as a client and a >server? I don't know for certain but I don't >think that should work. >Two computers? -- >Alexander
it should work. I did short tutorial on this like a month ago and it worked. The only difference is that in mine it didn't have the part below which is the source of the problem. Also, in mine, I used "send" and "recv" though I doubt this makes any difference. > ssl_sock = ssl.wrap_socket(s, > ca_certs="/home/ckyang/PHA/testsslsocket/ myCA.crt", > cert_reqs=ssl.CERT_REQUIRED) > ssl_sock.connect(("127.0.0.1", 1234)) On 15/12/2011, tutor-requ...@python.org <tutor-requ...@python.org> wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. Re: Localhost client-server simple ssl socket test program > problems (Alexander) > 2. timeit() help (Robert Sjoblom) > 3. [TUTOR]Code Deciphering (Calle) > 4. Re: [TUTOR]Code Deciphering (Robert Sjoblom) > 5. modify values for object derived from datetime.datetime > (rail shafigulin) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 15 Dec 2011 14:24:37 -0500 > From: Alexander <rhettna...@gmail.com> > To: Yang Chun-Kai <waitmefore...@hotmail.com> > Cc: python-l...@python.org, tutor@python.org > Subject: Re: [Tutor] Localhost client-server simple ssl socket test > program problems > Message-ID: > <CANS6qmBmSVefw=2-tbtzt472nr86ddoo3jubytm4ottpxgq...@mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > 2011/12/15 Yang Chun-Kai <waitmefore...@hotmail.com> > >> Hello,everyone!! >> >> I am writing a simple ssl client-server test program on my personal >> laptop. >> >> And I encounter some problems with my simple programs. >> >> Please give me some helps. >> >> -------------------------------------------------------------------------------------------------------------------------------------------------------- >> >> My server code: >> >> import socket >> import ssl >> bindsocket = socket.socket() >> bindsocket.bind(('127.0.0.1', 1234)) >> bindsocket.listen(5) >> print 'server is waiting for connection...' >> newsocket, fromaddr = bindsocket.accept() >> print 'start ssl socket...' >> connstream = ssl.wrap_socket(newsocket, server_side=True, >> certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", >> keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", >> ssl_version=ssl.PROTOCOL_SSLv23) >> data = connstream.read() >> print 'connected from address', fromaddr >> print 'received data as', repr(data) >> connstream.close() >> >> My client code: >> >> import socket >> import ssl >> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >> ssl_sock = ssl.wrap_socket(s, >> ca_certs="/home/ckyang/PHA/testsslsocket/myCA.crt", >> cert_reqs=ssl.CERT_REQUIRED) >> ssl_sock.connect(("127.0.0.1", 1234)) >> ssl_sock.write("hello") >> ssl_sock.close() >> >> >> ----------------------------------------------------------------------------------------------------------------------------------------------------------- >> Server side error: >> >> File "views.py", line 17, in & lt;module> >> connstream = ssl.wrap_socket(newsocket, server_side=True, >> certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", >> keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", >> ssl_version=ssl.PROTOCOL_SSLv23) >> File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socket >> ciphers=ciphers) >> File "/usr/lib/python2.7/ssl.py", line 119, in __init__ >> ciphers) >> ssl.SSLError: [Errno 336265218] _ssl.c:347: error:140B0002:SSL >> routines:SSL_CTX_use_PrivateKey_file:system lib >> >> Client side error: >> >> File "client.py", line 10, in <module> >> ssl_sock.connect(("127.0.0.1", 1234)) >> File "/usr/lib/python2.7/ssl.py", line 299, in connect** >> self.do_handshake() >> File "/usr/lib/python2.7/ssl.py", line 283, in do_handshake >> self._sslobj.do_handshake() >> socket.error: [Errno 104] Connection reset by peer >> >> >> ------------------------------------------------------------------------------------------------------------------------------------------------------------ >> So what is wrong with my code? >> >> The codes are so simple and so much like python official site sample >> demonstration, but I still cant get it work, so frustrating. >> >> Seems the problem happened on server side then cause client side cant >> connect well, is that right? >> >> ** >> My platform is ubuntu, with openssl 0.9.8 and python 2.7. >> >> All certificates and keys self-signed by openssl for test convenience. >> >> This is the site for referrence : >> http://andyjeffries.co.uk/articles/x509-encrypted-authenticated-socket-ruby-client >> >> Or should I need a real certificate issued by a real CA to let things >> work? >> >> Any tips or suggestions welcomed, thank you very much~ >> >> Good day. >> >> Kay >> >> ** >> >> _______________________________________________ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> >> > You're trying to connect to the same port on localhost as a client and a > server? I don't know for certain but I don't think that should work. > Two computers? > > > -- > Alexander > 7D9C597B > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://mail.python.org/pipermail/tutor/attachments/20111215/236b2679/attachment-0001.html> > > ------------------------------ > > Message: 2 > Date: Thu, 15 Dec 2011 20:59:29 +0100 > From: Robert Sjoblom <robert.sjob...@gmail.com> > To: Tutor - python List <tutor@python.org> > Subject: [Tutor] timeit() help > Message-ID: > <cajku7g2w8rjp83rnnc+5pzqh5wbqtzpaaiqnows-fuapwjm...@mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > So, it turns out that my ISP blocked Project Euler, so instead of > working on my next problem, I polished Problem 4 a bit: > >>A palindromic number reads the same both ways. The largest palindrome made >> from the product of two 2-digit numbers is 9009 = 91 ? 99. >>Find the largest palindrome made from the product of two 3-digit numbers. > > Those who don't want spoilers should look away. > > While it's perfectly fine to brute-force this (what I initially did) > with two for-loops, I wanted to make a better version. Here's the > code: > > First something to check whether a number is a palindrome: > def is_palindrome(number): > number = str(number) > return number == number[::-1] > > Then the crunching part: > > def biggest(): > big_x, big_y, max_seen = 0, 0, 0 > for x in range(999, 99, -1): > for y in range(x, 99, -1): #so we don't double count > if x*y < max_seen: continue #since we're decreasing > if is_palindrome(x*y): > big_x, big_y, max_seen = x, y, x*y > return big_x, big_y, max_seen > > However, I got to thinking... If we assume that the palindrome starts > with 9, it must end with 9 (I think that's a fair assumption, really > -- but it could come back and bite me I suppose). That means that the > only values for the third digit in each of the two factors would have > to be 1, 3, 7 or 9 (1 * 9, 3 * 3, 7 * 7 or 9 * 1). If we check for > this condition before checking whether a number is palindromic, we > ought to cut down on the numbers checked by, oh, I don't know... half, > at least? (it turns out that it's more: 405450 values, only 64980 have > 1, 3, 7 or 9 in the end), so in order to avoid checking some 340,000 > numbers, I wrote a third function: > > def check_value(number1, number2): > number1, number2 = str(number1), str(number2) > return number1[-1] in "1379" and number2[-1] in "1379" > > Putting this one inside the biggest() function, the final biggest() > function looks like this: > > def biggest(): > big_x, big_y, max_seen = 0, 0, 0 > for x in range(999, 99, -1): > for y in range(x, 99, -1): #so we don't double count > if check_value(x, y): #we ignore all numbers that > doesn't end in 1379 > if x*y < max_seen: continue #since we're decreasing > if is_palindrome(x*y): > big_x, big_y, max_seen = x, y, x*y > return big_x, big_y, max_seen > > My biggest problem now is that I don't know how to measure any changes > in efficiency. I know that the functions are working perfectly fine > as-is, and I shouldn't really optimize without a need to, but I'm > mostly curious as to whether the check_value() function is worth it or > not. To this I thought I'd use timeit(), but I can't for the life of > me work out how it works. At all. I've tried using it from the command > prompt, from the interpreter and in the code itself and it just > doesn't work. Or, it might very well work but it doesn't actually time > anything for me. It's very frustrating, but I feel like I'm too stupid > to read the official documentation for it (that is, I might understand > the words in the documentation, but I can't get it to work). Please > help? > > -- > best regards, > Robert S. > > > ------------------------------ > > Message: 3 > Date: Thu, 15 Dec 2011 22:09:20 +0100 > From: "Calle" <calle_pyt...@live.se> > To: <tutor@python.org> > Subject: [Tutor] [TUTOR]Code Deciphering > Message-ID: <dub109-ds323696802b29051022aa06f8...@phx.gbl> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > Hi! > > I was wondering, how do you use Python to decipher codes? It feels like it > should be pretty simple, but I haven't found any tutorials about it yet. > > Have a nice day! > // > Calle > > > > ------------------------------ > > Message: 4 > Date: Thu, 15 Dec 2011 22:34:41 +0100 > From: Robert Sjoblom <robert.sjob...@gmail.com> > To: Calle <calle_pyt...@live.se> > Cc: tutor@python.org > Subject: Re: [Tutor] [TUTOR]Code Deciphering > Message-ID: > <CAJKU7g1fq=sledo0gncjkzobe30ozj9v2z4opnfx3kwbfzg...@mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > >> I was wondering, how do you use Python to decipher codes? It feels like it >> should be pretty simple, but I haven't found any tutorials about it yet. > > What kind of codes? Or do you mean ciphers? Generally speaking, a code > represent letters or numbers in transmitting a message. In other > words, a code deals with phrases and sentences or whole words. Example > "steal the cabbage at dawn" could mean "kill the king on wednesday". > > A cipher deals with letters. It is a message written in letters in a > predetermined code. This means that a cipher is a system of > communication that uses letters instead of phrases. Examples being the > standard Caesar cipher where "APPLE" might be written "BQQMB" (ie, > shifted one letter to the right). > -- > best regards, > Robert S. > > > ------------------------------ > > Message: 5 > Date: Thu, 15 Dec 2011 17:01:28 -0500 > From: rail shafigulin <rail.shafigu...@gmail.com> > To: tutor@python.org > Subject: [Tutor] modify values for object derived from > datetime.datetime > Message-ID: > <cafaaerxoeatx9c-gbjgz2orjaoxfsmx41ef1soseu+qpq0w...@mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > i writing some code to do device testing at my work. testing is related to > date and time, so naturally i decided to create a class that inherits from > datetime.datetime. main reason is that i need to add, subtract and compare > datetime objects and datetime.datetime allows me to do that. here is the > code: > > class LTime(datetime.datetime): > TOLERANCE = 10 > > def __new__(self, year, month, day, *args): > if year == 0: > year = 2000 > > return super().__new__(self, year, month, day, *args) > > def modify(self): > self = self.replace(2012, 12, 12) > print(self) > > > def main(): > mytime = LTime.now() > mytime.modify() > print(mytime) > > if __name__ == '__main__': > main() > > the problem that i see is that i'm not able to modify date and time because > it seems that those attributes are immutable. another problem that i see is > in the modify() routine. if you print mytime the date and time are still > old. can anybody explain why this is happening and if it is even possible > to achieve what i'm trying to achieve, which is to change self.date and > self.time > > any help is appreciated. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://mail.python.org/pipermail/tutor/attachments/20111215/50d3b6bb/attachment.html> > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 94, Issue 57 > ************************************* > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor