Show
Ignore:
Timestamp:
02/24/10 14:01:29 (7 months ago)
Author:
Pablo Hoffman <pablo@…>
Branch:
default
Message:

Fixed encoding issue (reported in #135) when the encoding declared in the HTTP header is unknown. This is the patch proposed by Rolando, with an update to the Request/Response documentation.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • scrapy/http/response/text.py

    r1809 r1936  
    66""" 
    77 
     8import codecs 
    89import re 
    910 
     
    6566            encoding = self._ENCODING_RE.search(content_type) 
    6667            if encoding: 
    67                 return encoding.group(1) 
     68                enc = encoding.group(1) 
     69                try: 
     70                    codecs.lookup(enc) # check if the encoding is valid 
     71                    return enc 
     72                except LookupError: 
     73                    pass 
    6874 
    6975    @memoizemethod_noargs