URL: https://linuxfr.org/forums/programmation-python/posts/lecture-dun-stream-%C3%A0-partir-dun-fichier-sur-le-web Title: Lecture d'un stream à partir d'un fichier sur le web ? Authors: jayp Date: 2006年09月06日T00:47:28+02:00 Tags: Score: 0 Bonjour, Je cherche à lire un stream en python. Si le stream à lire sort d'un port d'un hôte, c'est très facile. Le code de la documentation Python suffit : HOST = 'host.com' PORT = 8000 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) data = s.recv(1024) s.close() print 'Received', repr(data) Maintenant, je cherche à lire un stream audio à partir d'un _fichier_ (et pas simplement un hôte). L'URL complète est (par exemple) : [http://streaming.rtbf.be:8000/pure128x8558](http://streaming.rtbf.be:8000/pure128x8558) J'ai essayé ceci mais çà ne fonctionne pas : import socket INHOST = "streaming.rtbf.be" INPORT = 8000 INPATH = "/pure128x8558" inSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) inSock.connect((INHOST, INPORT)) # pour recevoir l'info à partir du fichier voulu en HTTP (marche pas ?) : inSock.send("GET " + INPATH + "HTTP/1.0\r\nHost: " + INHOST + "\r\n\r\n") i = 0 while i <= 10: £spaces£ £/spaces£data = inSock.recv(2048) £spaces£ £/spaces£if not data: £spaces£ £/spaces£print "no data, i = " + str(i) £spaces£ £/spaces£break £spaces£ £/spaces£print str(i) + ". Read ", len(data), " bytes" £spaces£ £/spaces£i = i + 1 inSock.close() Je n'arrive qu'à recevoir aucune donnée. Est-ce que quelqu'un pourrait me dire ce qui ne va pas dans mon code ? Un grand merci d'avance.