Raise Error Ebadf Bad
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
Errno 9 Bad File Descriptor Python
site About Us Learn more about Stack Overflow the company Business Learn socket bad file descriptor python more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question python bad file descriptor 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: Sign up Python
Python Socket Close
socket (Socket Error Bad File Descriptor) up vote 9 down vote favorite The following receiveFile() function reads a filename and file data from the socket and splits it using the delimiter $. But I am unable to close the socket and a Bad file descriptor error is raised. If I comment out the self.server_socket.close() statement then there is no error but the socket is
Ioerror: [errno 9] Bad File Descriptor
listening forever. Code:- def listen(self): self.server_socket.listen(10) while True: client_socket, address = self.server_socket.accept() print 'connected to', address self.receiveFile(client_socket) def receiveFile(self,sock): data = sock.recv(1024) data = data.split("$"); print 'filename', data[0] f = open(data[0], "wb") #data = sock.recv(1024) print 'the data is', data[1] f.write(data[1]) data = sock.recv(1024) while (data): f.write(data) data=sock.recv(1024) f.close() self.server_socket.close() print 'the data is', data print "File Downloaded" Traceback:- Traceback (most recent call last): File "server.py", line 45, in a = Server(1111) File "server.py", line 15, in __init__ self.listen() File "server.py", line 20, in listen client_socket, address = self.server_socket.accept() File "c:\Python27\lib\socket.py", line 202, in accept sock, addr = self._sock.accept() File "c:\Python27\lib\socket.py", line 170, in _dummy raise error(EBADF, 'Bad file descriptor') socket.error: [Errno 9] Bad file descriptor python sockets share|improve this question edited Aug 7 '15 at 15:25 Alex Lisovoy 2,23511020 asked May 5 '13 at 8:50 Ali Ahmad 52531233 1 The error is probably not from that code, but wherever you're calling self.server_socket.accept() - would help to include a bit more of the code, and the full traceback. –Aya May 5 '13 at 8:58 So, is the idea you want the server to shut d
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta python socket select Discuss the workings and policies of this site About Us Learn
Python Socket Timeout
more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack python socket example Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, http://stackoverflow.com/questions/16382899/python-socket-socket-error-bad-file-descriptor helping each other. Join them; it only takes a minute: Sign up 'socket.error: [Errno 9] Bad file descriptor' as I run my client up vote 0 down vote favorite as I run my client, my server collapse, it says: Traceback (most recent call last): File "C:/Users/Or/PycharmProjects/2.6/cyber.py", line 17, in data = client_socket.recv(1024) File "C:\Python27\lib\socket.py", line 174, http://stackoverflow.com/questions/34238713/socket-error-errno-9-bad-file-descriptor-as-i-run-my-client in _dummy raise error(EBADF, 'Bad file descriptor') socket.error: [Errno 9] Bad file descriptor server: import socket import random import time server_socket = socket.socket() server_socket.bind(('0.0.0.0', 8820)) server_socket.listen(1) (client_socket, client_address) = server_socket.accept() TIME = time.asctime(time.localtime()) NAME = "Frank" RAND = random.randrange(1,10) EXIT = client_socket.close() options = [TIME, NAME, RAND, EXIT] data = client_socket.recv(1024) if data == str(TIME): client_socket.send('Time is: ' + TIME) elif data == str(NAME): client_socket.send('My name is: ' + NAME) elif data == str(RAND): client_socket.send(RAND) elif data == str(EXIT): EXIT client_socket.close() server_socket.close() client: import socket my_socket = socket.socket() my_socket.connect(('127.0.0.1', 8820)) theData = raw_input("enter command") options = ['TIME', 'NAME', 'RAND', 'EXIT'] for z in options: if theData == z: my_socket.send(theData) data = my_socket.recv(1024) print data else: theData = raw_input("enter a real command") what should I do? python python-2.7 sockets errno share|improve this question edited Dec 12 '15 at 13:29 Valijon 1,7742726 asked Dec 12 '15 at 10:20 Or Azari 12 iterate a closed port. which ending socket session, server, client ? Always server forever why ? How to ch
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 http://stackoverflow.com/questions/36966374/why-do-i-get-a-bad-file-descriptor-error Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a https://bugs.python.org/issue13344 community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up why do i get a bad file descriptor error? up vote 2 down vote favorite i bad file got an error for bad file descriptor for this code for the udp server program i made from socket import * s = socket(AF_INET, SOCK_DGRAM) s.bind(('', 890)) while True: (c,a) = s.recvfrom(1024) msg = 'thanks for requesting' s.sendto(msg,a) s.close() the error message i got was Traceback (most recent call last): File "udpserv.py", line 7, in (c,a) = s.recvfrom(1024) File "/usr/lib/python2.7/socket.py", line 174, in _dummy raise error(EBADF, 'Bad file descriptor') socket.error: bad file descriptor [Errno 9] Bad file descriptor can anyone please tell me how i got this error and how to solve it? python python-2.7 sockets server share|improve this question edited May 1 at 12:21 codran 1,596717 asked May 1 at 11:57 Ravi Krishnamoorthy 91 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote You get this error because you close the socket and then call recvfrom again. If you add a print after the line with recvfrom, you'll notice that the first call to recvfrom works as expected. The second call (after looping once) throws the error you see. Fix your code by simply removing s.close(). (You don't need to close the connection to the client as UDP doesn't have that concept, in contrast to TCP if you had that in mind.) share|improve this answer edited May 1 at 12:23 answered May 1 at 12:10 fuenfundachtzig 2,30443154 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 lookin
User List Committer List Help Tracker Documentation Tracker Development Report Tracker Problem Issue13344 classification Title: closed sockets don't raise EBADF anymore Type: behavior Stage: Components: Library (Lib) Versions: Python 3.2, Python 3.3 process Status: open Resolution: Dependencies: Superseder: Assigned To: Nosy List: colinmarc, exarkun, giampaolo.rodola, martin.panter, pconnell, pitrou Priority: low Keywords: Created on 2011-11-04 21:14 by pitrou, last changed 2016-06-24 02:20 by martin.panter. Messages (3) msg147039 - (view) Author: Antoine Pitrou (pitrou) * Date: 2011-11-04 21:14 This decrepancy between 2.x and 3.x is witnessed under Windows: Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> sock = socket.create_connection(("www.python.org", 80)) >>> sock.close() >>> sock.send(b"x") Traceback (most recent call last): File "", line 1, in File "c:\python27\lib\socket.py", line 170, in _dummy raise error(EBADF, 'Bad file descriptor') socket.error: [Errno 9] Bad file descriptor Python 3.2.1 (default, Jul 10 2011, 20:02:51) [MSC v.1500 64 bit (AMD64)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> sock = socket.socket(); sock.connect(("www.python.org", 80)) >>> sock.close() >>> sock.send(b"x") Traceback (most recent call last): File "", line 1, in socket.error: [Errno 10038] An operation was attempted on something that is not a socket I'm not sure this is worth fixing, though. msg147041 - (view) Author: Antoine Pitrou (pitrou) * Date: 2011-11-04 21:21 discrepancy, not decrepancy :S (10038 is WSAENOTSOCK, by the way) msg269148 - (view) Author: Martin Panter (martin.panter) * Date: 2016-06-24 02:20 According to strace, Python 3 is calling send(-1, ...): sendto(-1, "x", 1, 0, NULL, 0) = -1 EBADF (Bad file descriptor) A related discrepancy between Python 2 and 3 is how the socket.makefile() objects affect the original socket. In Python 2: >>> f = sock.makefile("wb") >>> sock.close() # Should “close” Python’s sock object, but not f >>> sock.send(b"x") socket.error: [Errno 9] Bad file descriptor In Python 3: >>> sock.send(b"x") # Actually sent to remote end! 1 History Date User Action Args 2016-06-2402:20:45martin.pantersetnosy: + martin.pantermessages: + msg269148 2013-11-2313: