Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: LookupError: unknown encoding: hex

I'm using a Twitter API called Tweepy. It has been working fine, then I rebooted the server and now I'm getting this:

>>> import tweepy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tweepy/__init__.py", line 17, in <module>
    from tweepy.streaming import Stream, StreamListener
  File "tweepy/streaming.py", line 16, in <module>
    json = import_simplejson()
  File "tweepy/utils.py", line 83, in import_simplejson
    import simplejson as json
  File "build/bdist.linux-i686/egg/simplejson/__init__.py", line 111, in <module>

  File "build/bdist.linux-i686/egg/simplejson/decoder.py", line 29, in <module>
  File "build/bdist.linux-i686/egg/simplejson/decoder.py", line 21, in _floatconstants
LookupError: unknown encoding: hex

I tried this too:

from encodings import hex_codec

And it didn't help.

Any ideas why?

like image 999
Zeno Avatar asked Oct 09 '22 18:10

Zeno


2 Answers

I've been experiencing the same problem (with json), the solution is to copy missing 'hex_codec.py' file at your 'encodings' Lib folder:

Make sure you have Python 2.7.X installed (you'll find it useful later).

  1. Go to your Python 2.7.X installation directory for 'encodings' folder (ex. for Win platform: 'C:\Python27\Lib\encodings')
  2. Copy 'hex_codec.py' or every single '.py' file to your 'build/bdist.linux-i686/egg/encodings' folder. ...
  3. PROFIT
like image 172
antontama Avatar answered Oct 12 '22 08:10

antontama


I've encounter this problem too, but it happed on a computer that I didn't have access to.

I've renamed encodings/hex_codec.py (and deleted the .pyc) look like what will make this error happen

ActivePython 2.7.0.2 (ActiveState Software Inc.) based on
Python 2.7 (r27:82500, Aug 23 2010, 17:18:21) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python27\lib\json\__init__.py", line 108, in <module>
    from .decoder import JSONDecoder
  File "c:\Python27\lib\json\decoder.py", line 24, in <module>
    NaN, PosInf, NegInf = _floatconstants()
  File "c:\Python27\lib\json\decoder.py", line 18, in _floatconstants
    _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
LookupError: unknown encoding: hex
>>>

check your files, hex_encoding is probably missing. or you might have something weird in your PATH / PYTHON_HOME

can you do printenv before running you code ? and "print sys.path" in the interpreter ?

like image 45
Fruch Avatar answered Oct 12 '22 10:10

Fruch