简体   繁体   English

Python:LookupError:未知编码:十六进制

[英]Python: LookupError: unknown encoding: hex

I'm using a Twitter API called Tweepy. 我正在使用名为Tweepy的Twitter API。 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? 有什么想法吗?

I've been experiencing the same problem (with json), the solution is to copy missing 'hex_codec.py' file at your 'encodings' Lib folder: 我遇到了同样的问题(使用json),解决方案是在'encodings'Lib文件夹中复制丢失的'hex_codec.py'文件:

Make sure you have Python 2.7.X installed (you'll find it useful later). 确保安装了Python 2.7.X(稍后你会发现它很有用)。

  1. Go to your Python 2.7.X installation directory for 'encodings' folder (ex. for Win platform: 'C:\\Python27\\Lib\\encodings') 转到“编码”文件夹的Python 2.7.X安装目录(例如,对于Win平台:'C:\\ Python27 \\ Lib \\ encodings')
  2. Copy 'hex_codec.py' or every single '.py' file to your 'build/bdist.linux-i686/egg/encodings' folder. 将'hex_codec.py'或每个'.py'文件复制到'build / bdist.linux-i686 / egg / encodings'文件夹中。 ... ...
  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 我已经重命名了编码/ hex_codec.py(并删除了.pyc)看起来会发生什么会导致这个错误发生

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. 检查你的文件,hex_encoding可能会丢失。 or you might have something weird in your PATH / PYTHON_HOME 或者你的PATH / PYTHON_HOME中可能有些怪异的东西

can you do printenv before running you code ? 你能在运行代码之前做printenv吗? and "print sys.path" in the interpreter ? 和解释器中的“print sys.path”?

I got the same problem trying android-python27 ( https://code.google.com/p/android-python27/issues/detail?id=30 ). 我在尝试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. 通过从PyPy复制binascii.py版本解决,并修改为尝试binascii.so并回退到pure-python如果无法导入二进制文件。

Get the result here: https://gist.github.com/alanjds/6091309 在此处获取结果: https//gist.github.com/alanjds/6091309

Have your changed your Python installation? 你改变了你的Python安装吗? In 3.x, there seem to be less codecs than in 2.x. 在3.x中,似乎比2.x中的编解码器少。 Especially, hex and base64 are missing, AFAIK. 特别是,缺少hexbase64 ,AFAIK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM