如何获得urllib3和请求使用jython 2.7 beta 1?

时间:2022-01-27 10:09:58

Smart folks,

聪明的人,

I would like to use the awesome requests module in my jython program. It installs and runs just fine in python but I cannot get it to install in jython. I have tried both Jython 2.7a2 and 2.7b1 on mac and ubuntu and get the same errors related to urllib3.

我想在jython程序中使用awesome request模块。它在python中安装并运行良好,但我无法让它在jython中安装。我在mac和ubuntu上试用了Jython 2.7a2和2.7b1,并得到了与urllib3相同的错误。

First installed ez_setup.py as mentioned in How can I use jython setup.py install?

第一次安装ez_setup。如前所述,我如何使用jython设置。py安装?

Then run easy_install from within the jython bin directory results in exception:

然后,在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

Looks like problem related to urllib3 not working with jython. Appreciate help in getting requests (and urllib3 ) to work on jython. The same error shows up on ubuntu as well.

看起来与urllib3有关的问题与jython无关。感谢帮助在获得请求(和urllib3)上对jython进行工作。同样的错误也出现在ubuntu上。

Thanks Gautam

由于Gautam

2 个解决方案

#1


7  

Edit: as of May 2015, the current stable version of requests, 2.7.0, no longer suffers from the original error in Jython --Aprillion

编辑:截止到2015年5月,当前稳定版本的请求,2.7.0,不再在Jython中出现原来的错误——Aprillion。


The bug you are facing has been fixed some time ago in the development versions of urllib3 and requests.

在urllib3的开发版本和请求中,您所面对的bug已经被修复了。

As you won't be able to install it as it will blow up pip/easy_install with java.lang.RuntimeException: java.lang.RuntimeException: Class file too large! you have to run it directly from the source tree.

因为您将无法安装它,因为它将使用java.lang来放大pip/easy_install。RuntimeException:. lang。运行时异常:类文件太大!您必须直接从源树运行它。

There you can fix the import bug by replacing all of the ssl_wrap_socket stuff at the end of requests/packages/urllib3/util.py with a dummy method like:

在那里,您可以通过在请求/包/urllib3/util的末尾替换所有ssl_wrap_socket内容来修复导入错误。用虚拟的方法,比如:

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')

(If ssl support is a concern to you: it is broken at the moment anyways)

(如果ssl支持对您来说是一个问题:它在任何时候都被破坏了)

As jython is missing support for idna you have to remove this too. Go to line 290 of request/models.py and replace 'idna' by 'utf-8'.

由于jython缺少对idna的支持,您必须删除它。请到第290行请求/模型。py,用utf-8替换“idna”。

So if you don't need to use ssl or idna those steps should work.

因此,如果您不需要使用ssl或idna,这些步骤应该有效。

Followup: The relevant ssl bug in jython is tracked here: http://bugs.jython.org/issue2016

追踪:在jython中相关的ssl bug被跟踪到这里:http://bugs.jython.org/2016/2016。

#2


1  

This problem has been resolved - please use Jython 2.7 beta 4 (or the final release).

这个问题已经解决——请使用Jython 2.7 beta 4(或最终版本)。

#1


7  

Edit: as of May 2015, the current stable version of requests, 2.7.0, no longer suffers from the original error in Jython --Aprillion

编辑:截止到2015年5月,当前稳定版本的请求,2.7.0,不再在Jython中出现原来的错误——Aprillion。


The bug you are facing has been fixed some time ago in the development versions of urllib3 and requests.

在urllib3的开发版本和请求中,您所面对的bug已经被修复了。

As you won't be able to install it as it will blow up pip/easy_install with java.lang.RuntimeException: java.lang.RuntimeException: Class file too large! you have to run it directly from the source tree.

因为您将无法安装它,因为它将使用java.lang来放大pip/easy_install。RuntimeException:. lang。运行时异常:类文件太大!您必须直接从源树运行它。

There you can fix the import bug by replacing all of the ssl_wrap_socket stuff at the end of requests/packages/urllib3/util.py with a dummy method like:

在那里,您可以通过在请求/包/urllib3/util的末尾替换所有ssl_wrap_socket内容来修复导入错误。用虚拟的方法,比如:

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')

(If ssl support is a concern to you: it is broken at the moment anyways)

(如果ssl支持对您来说是一个问题:它在任何时候都被破坏了)

As jython is missing support for idna you have to remove this too. Go to line 290 of request/models.py and replace 'idna' by 'utf-8'.

由于jython缺少对idna的支持,您必须删除它。请到第290行请求/模型。py,用utf-8替换“idna”。

So if you don't need to use ssl or idna those steps should work.

因此,如果您不需要使用ssl或idna,这些步骤应该有效。

Followup: The relevant ssl bug in jython is tracked here: http://bugs.jython.org/issue2016

追踪:在jython中相关的ssl bug被跟踪到这里:http://bugs.jython.org/2016/2016。

#2


1  

This problem has been resolved - please use Jython 2.7 beta 4 (or the final release).

这个问题已经解决——请使用Jython 2.7 beta 4(或最终版本)。