开发者

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开发者_StackOverflow社区
  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?


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


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 ?


I got the same problem trying android-python27 (https://code.google.com/p/android-python27/issues/detail?id=30).

Solved by copying binascii.py version from PyPy, and modifying to try binascii.so and fallback to pure-python if cannot import the binary one.

Get the result here: https://gist.github.com/alanjds/6091309


Have your changed your Python installation? In 3.x, there seem to be less codecs than in 2.x. Especially, hex and base64 are missing, AFAIK.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜