python demjson 库 报错:AttributeError: 'dict' object has no attribute 'has_key'
Traceback (most recent call last):
File "/root/github/stock/fund/stop_purchase_lof_fund.py", line 82, in fund_purchase_em
data_json = demjson.decode(data_text.strip("var db="))
File "/root/miniconda3/lib/python3.9/site-packages/demjson.py", line 2039, in decode
j = JSON( strict=strict )
File "/root/miniconda3/lib/python3.9/site-packages/demjson.py", line 910, in __init__
self._asciiencodable = [32 <= c < 128 and not self._rev_escapes.has_key(chr(c))
File "/root/miniconda3/lib/python3.9/site-packages/demjson.py", line 910, in <listcomp>
self._asciiencodable = [32 <= c < 128 and not self._rev_escapes.has_key(chr(c))
AttributeError: 'dict' object has no attribute 'has_key'
对比了一下demjson这个库的版本,原来是旧版本的问题。
于是 去升级demjson的版本。
结果,又遇到下面的问题:
38a0fdd9c4c11f8bf3b13fe77bc2a128307f965c8d5fb4dc6d6f6beb79 (from http://mirrors.tencentyun.com/pypi/simple/demjson/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Downloading http://mirrors.tencentyun.com/pypi/packages/90/ad/1bc63e6dd7714640ad775cf4773d790794084444617e8fee65834b98ceb0/demjson-2.2.3.tar.gz (131 kB)
|████████████████████████████████| 131 kB 4.2 MB/s
ERROR: Command errored out with exit status 1:
command: /root/miniconda3/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-h6u09lvf/demjson_eb4df5ca7a414740a8baec070239e4b3/setup.py'"'"'; __file__='"'"'/tmp/pip-install-h6u09lvf/demjson_eb4df5ca7a414740a8baec070239e4b3/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-shye_4u9
cwd: /tmp/pip-install-h6u09lvf/demjson_eb4df5ca7a414740a8baec070239e4b3/
Complete output (3 lines):
/root/miniconda3/lib/python3.9/site-packages/setuptools/dist.py:757: UserWarning: Usage of dash-separated 'index-url' will not be supported in future versions. Please use the underscore name 'index_url' instead
warnings.warn(
error in demjson setup command: use_2to3 is invalid.
一波未平,一波又起。
解决办法:
降级setuptool
pip install "setuptools<58.0.0"
然后就可以正常使用demjson了。