聪明的人,
我想在我的jython程序中使用awesome requests模块。它在python中安装和运行得很好,但我无法在jython中安装它。我在mac和ubuntu上尝试了Jython 2.7a2和2.7b1,并获得了与urllib3相关的相同错误。
首先安装了How can I use jython setup.py install?
中提到的ez_setup.py然后从jython bin目录中运行easy_install导致异常:
NameError: name 'CERT_NONE' is not defined
gautam-mbp:bin gautam$ ./easy_install requests
Searching for requests
Reading http://pypi.python.org/simple/requests/
Reading http://python-requests.org
Reading https://github.com/kennethreitz/requests
Best match: requests 1.1.0
Downloading http://pypi.python.org/packages/source/r/requests/requests-1.1.0.tar.gz#md5=a0158815af244c32041a3147ee09abf3
Processing requests-1.1.0.tar.gz
Running requests-1.1.0/setup.py -q bdist_egg --dist-dir /var/folders/jf/cb2pc45s7d94hd6sndysvyxw0000gn/T/easy_install-MnOao_/requests-1.1.0/egg-dist-tmp-E2Rkg1
Traceback (most recent call last):
File "./easy_install", line 7, in <module>
sys.exit(
File "/Users/gautam/jython27b1/Lib/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1712, in main
File "/Users/gautam/jython27b1/Lib/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1700, in with_ei_usage
File "/Users/gautam/jython27b1/Lib/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1712, in <lambda>
-----------lots of stack trace---------------
File "setup.py", line 6, in <module>
File "/var/folders/jf/cb2pc45s7d94hd6sndysvyxw0000gn/T/easy_install-MnOao_/requests-1.1.0/requests/__init__.py", line 52, in <module>
File "/var/folders/jf/cb2pc45s7d94hd6sndysvyxw0000gn/T/easy_install-MnOao_/requests-1.1.0/requests/utils.py", line 23, in <module>
File "/var/folders/jf/cb2pc45s7d94hd6sndysvyxw0000gn/T/easy_install-MnOao_/requests-1.1.0/requests/compat.py", line 7, in <module>
File "/var/folders/jf/cb2pc45s7d94hd6sndysvyxw0000gn/T/easy_install-MnOao_/requests-1.1.0/requests/packages/__init__.py", line 3, in <module>
File "/var/folders/jf/cb2pc45s7d94hd6sndysvyxw0000gn/T/easy_install-MnOao_/requests-1.1.0/requests/packages/urllib3/__init__.py", line 16, in <module>
File "/var/folders/jf/cb2pc45s7d94hd6sndysvyxw0000gn/T/easy_install-MnOao_/requests-1.1.0/requests/packages/urllib3/connectionpool.py", line 45, in <module>
File "/var/folders/jf/cb2pc45s7d94hd6sndysvyxw0000gn/T/easy_install-MnOao_/requests-1.1.0/requests/packages/urllib3/util.py", line 293, in <module>
NameError: name 'CERT_NONE' is not defined
看起来与urllib3相关的问题与jython不兼容。感谢获取请求(和urllib3)以处理jython的帮助。同样的错误也出现在ubuntu上。
由于 高塔姆
答案 0 :(得分:7)
编辑:截至2015年5月,requests, 2.7.0的当前稳定版本不再受到Jython中原始错误的影响--Aprillion
<小时/>
您在urllib3和requests的开发版本中已经修复了您所面临的错误。
由于您将无法安装它,因为它会使用java.lang.RuntimeException: java.lang.RuntimeException: Class file too large!
炸毁pip / easy_install,您必须直接从源树运行它。
您可以通过使用虚拟方法替换ssl_wrap_socket
末尾的所有requests/packages/urllib3/util.py
内容来修复导入错误:
def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
ca_certs=None, server_hostname=None,
ssl_version=None):
raise Error('This is not meant to be called')
(如果ssl支持是您关注的问题:它暂时被打破anyways)
由于jython missing支持idna,您必须删除它。
转到request/models.py
的第290行,将'idna'
替换为'utf-8
'。
因此,如果您不需要使用ssl或idna,那么这些步骤应该可以正常工作。
跟进: 在这里跟踪jython中的相关ssl错误:http://bugs.jython.org/issue2016
答案 1 :(得分:1)
此问题已得到解决 - 请使用Jython 2.7 beta 4(或最终版本)。