Spynner downloads a zero-byte .jpg with browser.download(url, filename) - Python, PHP -


here code have tried. files 0 bytes. i've set imagedata=br.download(...) , reports 0 len(). i've been @ hours... ideas?

pre_record_soup='[<img src='/show_pic.php?id=316600'>]' #simplified  def func_get_pic(pre_record_soup, br=spynner.browser()):     baseurl='http://www.testsite.com/'      record in pre_record_soup:         imagetag=record.find('img')         filename = 'image.jpg' #set name of file afterdownload          try:             if imagetag:                 piclink = imagetag.find('img')['src']             else:                 piclink = 'basicimages/icons/icon.gif'                 filename = 'icon.gif'         except typeerror:             return none          print baseurl+piclink #this prints expected link         print filename #this prints filename want          open('/home/myhome/'+filename, 'wb') handle:             br.download(baseurl+piclink,handle) #not retrieving image... 

i'm calling function within authenticated session spynner. spynner logs me website, , scrape , other data. other data (text) scrapes fine. additionally, when visit image url in browser displays jpeg file.

thanks help!

edit-10 march 2014//here debug message spynner gives me. note correctly formatted url php-served image, , lack of "read download stream" present in correctly downloaded .gif:

http://www.testsite.com/show_pic.php?id=81851 request: http://www.testsite.com/show_pic.php?id=81851 start download: http://www.testsite.com/show_pic.php?id=81851 download finished: http://www.testsite.com/show_pic.php?id=81851 http://www.testsite.com/basicimages/icons/icon.gif request: http://www.testsite.com/basicimages/icons/icon.gif start download: http://www.testsite.com/basicimages/icons/icon.gif read download stream (419 bytes): http://www.testsite.com/basicimages/icons/icon.gif download finished: http://www.testsite.com/basicimages/icons/icon.gif 

additional info-debug stream br.load attempt. note content-length 0 bytes. loads fine in firefox... ugh!

page load started request: http://www.testsite.com/show_pic.php?id=81851   accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8   user-agent: mozilla/5.0 (x11; linux x86_64) applewebkit/537.21 (khtml, gecko)     qt/4.8.4 safari/537.21 reply: 200/ok - http://www.testsite.com/show_pic.php?id=81851   date: tue, 11 mar 2014 01:16:35 gmt   server: apache   set-cookie: phpsessid=abvcv4j6hbu57a638tc8pg8i77b19bl0; path=/   content-length: 0   connection: close   content-type: text/html page load finished (39 bytes): http://www.testsite.com/show_pic.php?id=81851 (successful) 

according code, after parsing piclink has:

http://www.testsite.com/show_pic.php?id=316600

and doing baseurl+piclink means:

http://www.testsite.com/http://www.testsite.com/show_pic.php?id=316600

so know error. adjust url accordingly , solve problem!


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -