urllib.urlopen doesn't follow HTTP redirects - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: urllib.urlopen doesn't follow HTTP redirects (/showthread.php?tid=85515) |
urllib.urlopen doesn't follow HTTP redirects - jhsrennie - 2010-11-16 I want my addon to be able to download a file from Sourceforge, but this requires following *two* HTTP redirects. With Python 2.7 urllib.urlopen() automatically follows the redirects and downloads the file. When I use the same code in XBMC it doesn't follow the redirects and just downloads the "HTTP/1.1 302" page. Is there a difference in the version of Python used in XBMC (v2.4?) that causes the different behaviour and if so is there some setting I can tweak? Alternatively can anyone think of a way to get around the problem that doesn't involve parsing the HTML response and doing the redirects manually? Thanks, JR - Mnuu - 2010-11-17 You don't need to parse the HTML the new location should be part of the header, this should help you do it http://diveintopython.org/http_web_services/redirects.html - NordishByNature - 2010-11-18 Hello, there is a Python Lib called "Mechanize". It's a browser implementation which can handle redirects, forms etc. Look in Facebook Pictures Plugin for example! cu NordishByNature - jhsrennie - 2010-11-18 Thanks both. The thing is that urllib.urlopen does follow redirects in Python 2.7 without any messing around and I'd much prefer this to work with the version of Python used in XBMC. If I have to code up my own version of urlopen I will, but I'd prefer not to. Later: I installed Python 2.4.4 on my PC with that version urllib.urlopen also follows redirects. It seems to be just the Python interpreter in XBMC that's the problem. The offending code is: Code: _KEYMAPEDITURL = "http://sourceforge.net/projects/xbmcmce/files/KeyMapEdit.exe/download" This works when run on my PC with Python 2.4.4 (after changing the "dialog.ok" calls to "print" but not when run in XBMC. JR - Eldorado - 2011-04-10 Did you ever find a solution? I'm seeing similar results, works fine in Python 2.7 but returns wrong html in XBMC same as your problem - drascom - 2011-04-11 i try to handle the same problem described http://forum.xbmc.org/showpost.php?p=767870&postcount=1 i think mechanize solve our problem but we have to add neccesary file to our zip file... now time to read and learn new stuff - Eldorado - 2011-04-11 I've given mechanize a quick try but still getting the same results - fine in Python 2.7, wrong html returned in XBMC The addon you have listed in your sig, is that the one where you used it? http://code.google.com/p/turkishxbmcscraper/ - drascom - 2011-04-14 no just in my computer.i release that when i solve it. solved - drascom - 2011-04-14 i find the solution from Code: http://stackoverflow.com/questions/2353689/how-do-i-get-the-url-of-an-http-redirects-target urllib2.urlopen(my_url).geturl() give me my answer Code: [b]urllib2.urlopen('http://molasaati.com/molasaati.php?git=http://video.l3.fbcdn.net/cfs-l3-ash4/213405/495/202851533071086_58429.mp4').geturl()[/b] but i dont know how to use new url any help to continue code ? Code: url='http://www.sineman.net/jackass-3-d-hd-film-izle.html' Solved - drascom - 2011-04-14 Ok i find solution to continue my code. i hope it helps to someone.. Code: url='http://www.sineman.net/jackass-3-d-hd-film-izle.html' |