problem with socket.py

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with socket.py

Girish Joshi
Hello all
I'm writing a simple application to download youtube videos;
I've updated the jython interpreter I'm working with jython 2.7b2 as the required api is written in python 2.7
I'm using pafy api written in python (http://np1.github.io/pafy/) for that and for GUI i'm using SWT.
now the problem is some times the code works;
but some times it raises map_exception
socket.error: [Errno 32] Socket closed
my code is like
try:
                video =pafy.new( urlText.getText())
                details ={"title":video.title, "rating":video.rating, "views":video.viewcount, "author":video.author, "length":video.length , "dueration":video.duration, "likes":video.likes, "dislikes":video.dislikes }
                discreption = video.description
                for d in details:
                    print d+"     "+ str(details[d]).replace(u'\u2019', u'\'').encode('ascii', 'ignore')
                    streams =video.streams
                print "available strems"
                for s in streams:
                    print str(s).replace(u'\u2019', u'\'').encode('ascii', 'ignore')
                allstreams = video.allstreams
                print "all available Streams"
                for s in allstreams:
                    print str(s).replace(u'\u2019', u'\'').encode('ascii', 'ignore') + str(s.url).replace(u'\u2019', u'\'').encode('ascii', 'ignore')
                best = video.getbest()
            except Exception , err:
                print "error"+str(err)
                #streams =video.streams


the stack trace is


File "scratch.py", line 79, in <module>
    c = start()
  File "scratch.py", line 76, in __init__
    if (not self.display.readAndDispatch()):
  File "scratch.py", line 15, in handleEvent
    video =pafy.new( urlText.getText())
  File "/home/girish/jythonyt/trial/pafy.py", line 131, in new
    return Pafy(url, basic, gdata, signature, size, callback)
  File "/home/girish/jythonyt/trial/pafy.py", line 925, in __init__
    self.fetch_basic()
  File "/home/girish/jythonyt/trial/pafy.py", line 952, in fetch_basic
    allinfo = get_video_info(self.videoid)
  File "/home/girish/jythonyt/trial/pafy.py", line 138, in get_video_info
    info = fetch_decode(url)  # bytes
  File "/home/girish/jythonyt/trial/pafy.py", line 98, in fetch_decode
    return req.read()
  File "/home/girish/jythonhome/Lib/socket.py", line 1651, in read
    data = self._sock.recv(recv_size)
  File "/home/girish/jythonhome/Lib/httplib.py", line 543, in read
    return self._read_chunked(amt)
  File "/home/girish/jythonhome/Lib/httplib.py", line 603, in _read_chunked
    value.append(self._safe_read(amt))
  File "/home/girish/jythonhome/Lib/httplib.py", line 658, in _safe_read
    chunk = self.fp.read(min(amt, MAXAMOUNT))
  File "/home/girish/jythonhome/Lib/socket.py", line 1669, in read
    data = self._sock.recv(recv_size)
  File "/home/girish/jythonhome/Lib/socket.py", line 174, in handle_exception
    raise _map_exception(jlx)
socket.error: [Errno 32] Socket closed


so my question is how to make this code consistent? because some times it works.
can some one please help me with this?

thank you!
girish

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users
Reply | Threaded
Open this post in threaded view
|

Re: problem with socket.py

Dan Stromberg-2
On Wed, Aug 20, 2014 at 2:11 AM, Girish Joshi <[hidden email]> wrote:
> Hello all
> I'm writing a simple application to download youtube videos;

It looks to me like you may want to catch socket.error and retry.

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Jython-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jython-users