Permalink
Browse files

Adding a UTF hint to decode.

 Thanks for the report, @ehazlett.
  • Loading branch information...
Paul Tagliamonte
Paul Tagliamonte committed Feb 18, 2012
1 parent 931157a commit 0267f9df1e1ead78ebe712656e4bfca4cfc9fc1f
Showing with 10 additions and 2 deletions.
  1. +8 −0 ChangeLog
  2. +1 −1 sunlight/__init__.py
  3. +1 −1 sunlight/service.py
View
@@ -1,3 +1,11 @@
+2012-02-17 Paul Tagliamonte <paultag@sunlightfoundation.com
+
+* sunlight/service.py: Added a UTF hint to the .decode() call, it was
+resulting in a unicode error when translating UTF -> ASCII. This resulted in
+issue #170 in OpenStates.
+* Hotfix release, thanks ehazlett!
+* Bump release to 1.0.4
+
2012-02-17 Paul Tagliamonte <paultag@sunlightfoundation.com>
* Import InvalidRequestException to the IE module, thanks pyflakes!
View
@@ -11,7 +11,7 @@
"""
__appname__ = "sunlight"
-__version__ = "1.0.3"
+__version__ = "1.0.4"
import sunlight.services.openstates
import sunlight.services.capitolwords
View
@@ -56,7 +56,7 @@ def get(self, top_level_object, **kwargs):
**kwargs)
try:
r = urlopen(url)
- return_data = r.read().decode()
+ return_data = r.read().decode(encoding='UTF-8')
return self._decode_response(return_data)
except HTTPError as e:
message = e.read()

5 comments on commit 0267f9d

This fails for me. Running Python 2.6.1, I get a TypeError:

In [13]: bill = openstates.bill_detail( 'ca', '20092010', 'AB 667')
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (59, 0))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/Users/camico/code/python/php/<ipython-input-13-4c638147bc6f> in <module>()
----> 1 bill = openstates.bill_detail( 'ca', '20092010', 'AB 667')

/Users/camico/code/python/php/lib/python2.6/site-packages/sunlight/services/openstates.pyc in bill_detail(self, state, session, bill_id, chamber)
     57             lss.append(chamber)
     58         lss.append(bill_id)
---> 59         return self.get(lss)
     60 
     61     def legislators(self, **kwargs):

/Users/camico/code/python/php/lib/python2.6/site-packages/sunlight/service.pyc in get(self, top_level_object, **kwargs)
     57         try:
     58             r = urlopen(url)
---> 59             return_data = r.read().decode(encoding='UTF-8')
     60             return self._decode_response(return_data)
     61         except HTTPError as e:

TypeError: decode() takes no keyword arguments
Owner

paultag replied Feb 21, 2012

ACK'd, I'm on it.

Owner

paultag replied Feb 21, 2012

Looks to be fixed in 2.6, 2.7 and 3.x, can you verify this?

Yes, that worked. Thanks for the quick fix.

Owner

paultag replied Feb 21, 2012

You got it. I'll release an upload to PyPi in the next few hours. Thanks for the report!

Please sign in to comment.