Python 2.3 bug,urllib2 http error 206 work around?
#1
i'm trying to download partial content using the range header, but from what i understand python 2.3 has a bug that causes the script to stop on a 206 error. i saw an example of how to get around this using urllib, by making a class of urllib and overwritting that error with a pass. i'm new to python so i'm not sure how to do the same thing with urllib2.

if anyone has done partial content downloading with urllib2 could you post a little sample?

thanks very much...
hexp.
Reply
#2
well, i've partially figured it out. i can over ride the basehandler by doing something like this:
Quote:class httprangehandler(urllib2.basehandler):
"""
to override the urllib2 error: 'error 206: partial content'
this reponse from the http server is already what we expected to get.
don't give up, resume downloading..
"""

def http_error_206(self, request, fp, errcode, msg, headers):
return urllib.addinfourl(fp, headers, request.get_full_url())

and then building an opener, but i also need to use the basicauthhandler.

so at this point i can either download my file with username and password or download partial content, but not both...

if anyone can give me a hand figuring out how to build the opener correctly that would be great...

thanks again,
hexp.
Reply
#3
found it, i missed the fact that you can add more than 1 handler when building an opener.

i.e.

myopener = urllib2.build_opener(httprangehandler,auth_handler)

sorry about posting, seems as soon as you post a question, the answer some how jumps out in front of you...
Reply
#4
(hexperience @ jan. 01 2006,22:31 Wrote:...
sorry about posting, seems as soon as you post a question, the answer some how jumps out in front of you...
incredibly true. that has happened to me three times already. i am always so embarassed..
Reply
#5
(hexperience @ jan. 01 2006,20:31 Wrote:found it, i missed the fact that you can add more than 1 handler when building an opener.

i.e.

myopener = urllib2.build_opener(httprangehandler,auth_handler)

sorry about posting, seems as soon as you post a question, the answer some how jumps out in front of you...
hexperience,
this is ot but you seem to know urllib... can you help out with a problem we've been working on trying to post data to a web site?

your help is appreciated!

link to the current thread
I'm not an expert but I play one at work.
Reply
#6
affini, you need to create an asp page to post to.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#7
(nuka1195 @ jan. 02 2006,08:04 Wrote:affini, you need to create an asp page to post to.
according to the homeseer documentation i do not need to us asp. the simple http command should be accepted directly from a html page.

here's the page in the online manual for homeseer with the info:

homeseer info on controlling devices from html
I'm not an expert but I play one at work.
Reply
#8
hexperience / nuka

any other help you can give?
I'm not an expert but I play one at work.
Reply
#9
i found the issue... wrong commands being sent to server. it was not a python issue at all.

thanks for the help guys!
I'm not an expert but I play one at work.
Reply
#10
So...
Is it solved then?
Now I'm in trouble with GET with range:

19:16:16 M: 37187584 DEBUG: Curl:: Debug GET /resources/flv/1/7/1211393207671.flv HTTP/1.1
Range: bytes=Host: http://www.rtve.es
User-Agent: XBMC/pre-2.1 (compatible; MSIE 6.0; Windows NT 5.1; WinampMPEG/5.09)
Host: http://www.rtve.es
Accept: */*

Another example:

19:16:17 M: 33955840 DEBUG: Curl:: Debug GET /resources/flv/1/7/1211393207671.flv HTTP/1.1
Range: bytes=About to connect() to http://www.rtve.es port 80 (#0)
User-Agent: XBMC/pre-2.1 (compatible; MSIE 6.0; Windows NT 5.1; WinampMPEG/5.09)
Host: http://www.rtve.es
Accept: */*

Thanks
Reply
#11
I answer myself ;-)

Yes, it's solved. Last revision contains last libcurl.dll.
So, GET with ranges problems is ok now.
Reply

Logout Mark Read Team Forum Stats Members Help
Python 2.3 bug,urllib2 http error 206 work around?0