Python Socket.error Errno 9 Bad File Descriptor
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow errno 9 bad file descriptor python the company Business Learn more about hiring developers or posting ads with us Stack
Raise Error(ebadf, 'bad File Descriptor')
Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of connect:errno=9 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Getting Errno 9: Bad file descriptor in python socket up vote 8 down vote favorite 3 My code errno 9 socket is this: while 1: # Determine whether the server is up or down try: s.connect((mcip, port)) s.send(magic) data = s.recv(1024) s.close() print data except Exception, e: print e sleep(60) It works fine on the first run, but gives me Errno 9 every time after. What am I doing wrong? BTW, mcip = "mau5ville.com" port = 25565 magic = "\xFE" python sockets share|improve this question asked Apr 11 '13 at 20:13 Mike Savi
Bad File Descriptor Error In C
881110 1 What do magic, mcip, and port mean? Please post the full code on www.pastebin.com –xxmbabanexx Apr 11 '13 at 20:15 Added them for you –Mike Savi Apr 11 '13 at 20:17 add a comment| 1 Answer 1 active oldest votes up vote 19 down vote accepted You're calling connect on the same socket you closed. You can't do that. As for the docs for close say: All future operations on the socket object will fail. Just move the s = socket.socket() (or whatever you have) into the loop. (Or, if you prefer, use create_connection instead of doing it in two steps, which makes this harder to get wrong, as well as meaning you don't have to guess at IPv4 vs. IPv6, etc.) share|improve this answer answered Apr 11 '13 at 20:18 abarnert 165k11198275 Awesomeee. Thanks! –Mike Savi Apr 11 '13 at 20:20 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies socket bad file descriptor of this site About Us Learn more about Stack Overflow the company Business python bad file descriptor Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Ioerror:[errno 9] Bad File Descriptor
Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: http://stackoverflow.com/questions/15958026/getting-errno-9-bad-file-descriptor-in-python-socket Sign up What could be the reason for a socket error “[Errno 9] Bad file descriptor” up vote 5 down vote favorite I have a complex python (2.7.3) script which is trying to open a socket connection via self.socket.close() # doing something else self.socket.connect((host, port)) but all I get is the following socket error: error: [Errno 9] Bad file descriptor The host:port accepts http://stackoverflow.com/questions/17207051/what-could-be-the-reason-for-a-socket-error-errno-9-bad-file-descriptor connections as I have verified this with nc host port manually. So what could be the possible reasons I get this error for opening a connection to the given port, which actually works? I cannot and will not post the full script as it is too complex and irrelavent for this question. I just would like to know all possible reasons for this error, and how to check them and fix them. python sockets python-2.7 share|improve this question asked Jun 20 '13 at 6:53 Alex 7,7431767134 3 Read the documentation for socket.close(). You cannot reuse it in any operation (including connect) once you close it. It needs to be reinitialized with a call to socket.socket. –Thomas Jun 20 '13 at 6:58 add a comment| 1 Answer 1 active oldest votes up vote 18 down vote accepted You will need to create a new socket object. Maybe self.socket = socket.socket() after closing the previous socket and before connecting. share|improve this answer answered Jun 20 '13 at 6:58 Atmaram Shetye 661413 Bongo that's it! Thank you very much. –Alex Jun 20 '13 at 7:0
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies http://stackoverflow.com/questions/38292142/python-socket-error-errno-9-bad-file-descriptor of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=73016 Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: bad file Sign up python socket.error: [Errno 9] Bad file descriptor up vote 2 down vote favorite I wanted to make a server and a client with Python. It was supposed to make multiple connections, one, where the server is sending something to the client, and one where the client is sending something to the server. The first connection worked fine, but the second bad file descriptor one crashed with the message: socket.error: [Errno 9] Bad file descriptor Here is the Server: import socket import errno import pickle def Main(): host = '188.174.233.99' port = 66666 all_text = ['text1', 'text2', 'text3'] all_description = ['Test \n Description1\n', 'Test \n Description1\n', 'Test \n Description1\n'] all_images = ['unlock.png', 'unlock.png', 'unlock.png'] s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) s.bind((host, port)) s.listen(1) while True: c, addr = s.accept() c.setblocking(0) print "Connection from: " + str(addr) command = c.recv(1024) if command == 'GIVEALL': textstring = pickle.dumps([all_text, all_images, all_description])#verwandelt Liste in String c.send(textstring) else: try: new_event = pickle.loads(command) print new_event caption = new_event[0] image = new_event[1] describtion = new_event[2] city = new_event[3] except: pass try: c.close() s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) except socket.error as e: if e.errno != errno.ECONNRESET: raise pass if __name__ == '__main__': Main() And here is the Client: import socket import pickle from kivy.properties import StringProperty from kivy.properties import NumericProperty from kivy.properties import ListProperty class Netclient(object): def __init__(self): self.s = socket.socket() self.texte = [] self.current = 'All' self.ip = '188.174.233.99' self.port = 66666 def giveWid(self): print 'give Widgets executed' if self.current == 'All': self.texte, self.images, self.description = self.sentHOT(self.ip, self.port) return self.texte, self.images
Board index The team Delete all board cookies All times are UTC