Results 1 to 3 of 3

Thread: [Python] Problem with urllib2

  1. #1
    Join Date
    Aug 2009
    Location
    India, Tamilnadu
    Beans
    206
    Distro
    Kubuntu 15.10 Wily Werewolf

    Angry [Python] Problem with urllib2

    hi friends,
    I building a simple downloader application in python using urllib2.

    now i have a major problem with urllib2.

    i used this type of the code:
    PHP Code:
    import urllib2
    connection 
    urllib2.urlopen("http://softwareroxer.110mb.com/apps/rdm/rdm0.9-1alpha.deb.zip")
    rec_size 0
    fsize 
    connection.headers(["Content-Length"])
    while 
    1:
        
    Out connection.read(5*1024)  #5kb buffer
        
    rec_size len(Out)+rec_size
        
    if rec_size == fsize:
            print 
    "File size matched"
            
    break
        
    elif Out == "":
            print 
    "Empty output...."
            
    print rec_size,fsize
        
    else:pass 
    i think my code was correct, But urllib2 giving empty output ("") in the middle of the file.

    I have also tried with httplib, but the same error occurred.
    Note:
    i am using threads for this connections.

    whats wrong with urllib or my code, I can't get any ideas about this ,

    please help me friends.

    thanks in advance.
    Last edited by baskar007; January 17th, 2010 at 07:47 AM. Reason: bad english :) sorry

  2. #2
    Join Date
    Jan 2010
    Beans
    9

    Re: [Python] Problem with urllib2

    Code:
    import urllib2
    
    remoteFile = urllib2.urlopen("http://softwareroxer.110mb.com/apps/rdm/rdm0.9-1alpha.deb.zip")
    print "Remote file size:", remoteFile.info()["Content-Length"], "bytes"
    
    print "Reading 5x1024 bytes .."
    
    inBound = remoteFile.read(5*1024)
    dataLength = len(inBound)
    
    print "Received:", dataLength, "bytes"
    
    remoteFile.close()
    Code:
    Remote file size: 402764 bytes
    Reading 5x1024 bytes ..
    Received: 5120 bytes
    Last edited by Unlimited Bit; January 17th, 2010 at 03:20 PM.

  3. #3
    Join Date
    Aug 2009
    Location
    India, Tamilnadu
    Beans
    206
    Distro
    Kubuntu 15.10 Wily Werewolf

    Re: [Python] Problem with urllib2

    Quote Originally Posted by Unlimited Bit View Post
    Code:
    import urllib2
    
    remoteFile = urllib2.urlopen("http://softwareroxer.110mb.com/apps/rdm/rdm0.9-1alpha.deb.zip")
    print "Remote file size:", remoteFile.info()["Content-Length"], "bytes"
    
    print "Reading 5x1024 bytes .."
    
    inBound = remoteFile.read(5*1024)
    dataLength = len(inBound)
    
    print "Received:", dataLength, "bytes"
    
    remoteFile.close()
    Code:
    Remote file size: 402764 bytes
    Reading 5x1024 bytes ..
    Received: 5120 bytes
    i think you don't understand my Q. sorry for that.

    here is my problem:
    i want to download 402764 bytes size file. So i am using 5kb buffer in a while loop. after 201382 bytes completed urllib2 will give a empty output (that is 'len("")').

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •