[英]Python: LookupError: unknown encoding: hex
我正在使用名為Tweepy的Twitter API。 它一直工作正常,然后我重新啟動服務器,現在我得到這個:
>>> 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
我也試過這個:
from encodings import hex_codec
它沒有幫助。
有什么想法嗎?
我遇到了同樣的問題(使用json),解決方案是在'encodings'Lib文件夾中復制丟失的'hex_codec.py'文件:
確保安裝了Python 2.7.X(稍后你會發現它很有用)。
我也遇到過這個問題,但它在我無法訪問的計算機上發生了。
我已經重命名了編碼/ 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
>>>
檢查你的文件,hex_encoding可能會丟失。 或者你的PATH / PYTHON_HOME中可能有些怪異的東西
你能在運行代碼之前做printenv嗎? 和解釋器中的“print sys.path”?
我在嘗試android-python27時遇到了同樣的問題( https://code.google.com/p/android-python27/issues/detail?id=30 )。
通過從PyPy復制binascii.py版本解決,並修改為嘗試binascii.so並回退到pure-python如果無法導入二進制文件。
在此處獲取結果: https : //gist.github.com/alanjds/6091309
你改變了你的Python安裝嗎? 在3.x中,似乎比2.x中的編解碼器少。 特別是,缺少hex
和base64
,AFAIK。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.