2013-02-17 23 views
7

聰明的人,如何獲取urllib3和使用jython 2.7 beta 1的請求?

我想在我的jython程序中使用awesome requests模塊。它在python中安裝並運行得很好,但我無法用jython來安裝它。我已經在Mac和Ubuntu上嘗試了Jython 2.7a2和2.7b1,並獲得了與urllib3相關的錯誤。在How can I use jython setup.py install?

提到然後從異常Jython的bin目錄結果中的easy_install運行

先裝ez_setup.py:

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

這是一個錯誤。 :(剛剛提交,你可以在這裏跟蹤:https://github.com/shazow/urllib3/issues/150很快就會嘗試修復它,對於給您帶來的不便,我們深表歉意 – shazow 2013-02-19 03:27:52

+0

謝謝。Gautam – 2013-02-19 04:24:51

回答

7

編輯:爲2015年5月的,的requests, 2.7.0當前穩定版本,不再從原來的錯誤的Jython --Aprillion遭受


的錯誤你是面對已在前段時間在urllib3requests的開發版本中得到修復。

由於您將無法安裝它,因爲它會炸燬pip/easy_install與java.lang.RuntimeException: java.lang.RuntimeException: Class file too large!,您必須直接從源代碼樹運行它。

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支持是涉及您的利益:它在打破

在那裏,你可以通過一個虛擬的方法,像更換所有的ssl_wrap_socket東西在requests/packages/urllib3/util.py末修復導入錯誤anyways

由於jython是missing支持idna你也必須刪除它。 轉到request/models.py的第290行,並用'utf-8'替換'idna''。

所以,如果你不需要使用ssl或idna這些步驟應該工作。

跟帖: Jython中相關SSL錯誤在這裏追蹤:http://bugs.jython.org/issue2016

+0

今天會試一試 - 請給我一些關於如何安裝devll版本的urllib3和請求的信息? – 2013-02-20 21:43:48

+0

你不需要dev版本 從pypi下載[tar.gz文件](https://pypi.python.org /packages/source/r/requests/requests-1.1.0.tar.gz#md5=a0158815af244c32041a3147ee09abf3),解壓縮它,然後修改文件util.py和models,py,就像在答案中解釋的那樣。 然後嘗試使用它一個jython解釋器在解壓縮請求的目錄中啓動。 如果你想從其他地方使用它,你必須調整這個pythons路徑,這裏有文檔。 – 2013-02-20 22:03:58

+0

它的工作原理!謝謝,這很好。 – 2013-02-20 23:54:05

1

此問題已得到解決 - 請使用Jython的2.7測試版4(或最終版)。

+0

什麼時候會發布2.7版本?我還沒有看到它從這裏http://www.jython.org/downloads.html – brianray 2014-07-21 18:15:19

相關問題