Python Forum

Full Version: Need help converting some code from python 2.7 to 3.5
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This works great in 2.7, does not work in 3.5. I hope some one can tell me why?



import socket   #for sockets
import sys  #for exit
 
try:
    #create an AF_INET, STREAM socket (TCP)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
    print ('Failed to create socket. Error code: ') + str(msg[0]) + ' , Error message : ' + msg[1]
    sys.exit();
 
print ('Socket Created')
Line 7 is the problem I think
Thank you
Yes, it is indeed line 7...and 8 and 9  :)

it should look something like this:

import socket  # for sockets
import sys  # for exit

try:
    # create an AF_INET, STREAM socket (TCP)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error as msg:
    print('Failed to create socket. Error code: {}'.format(str(msg)))
    sys.exit()

print('Socket Created')
Yes, that works. Now I want to see what you did, then if you don't mind I would like to ask you a few things. Is that ok?
renny
(Oct-17-2016, 11:41 PM)Blue Dog Wrote: [ -> ]Yes, that works. Now I want to see what you did, then if you don't mind I would like to ask you a few things. Is that ok?
renny

That's why we are here  :D  and if I can't answer it, there is a 99.99 % chance someone else can :dance: