可以在 ironpython 2.7.5 中使用请求吗?
It's possible to use requests in ironpython 2.7.5?
我已经在 ironpython 上成功安装了 pip。但是当我尝试在管理员控制台中使用 "ipy.exe -X:Frames -m pip install requests" 安装请求时,我得到以下信息:
------------------------------------------------------------
C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\__main__.py run on 02/02/16 16:13:53
Downloading/unpacking html5lib
Getting page https://pypi.python.org/simple/html5lib/
Cleaning up...
Removing temporary dir c:\users\panta\appdata\local\temp\pip_build_panta...
Exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\req.py", line 1183, in prepare_files
url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\index.py", line 194, in find_requirement
page = self._get_page(main_index_url, req)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\index.py", line 566, in _get_page
return HTMLPage.get_page(link, req,
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\index.py", line 670, in get_page
resp = session.get(url, headers={"Accept": "text/html"})
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\sessions.py", line 468, in get
return self.request('GET', url, **kwargs)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\download.py", line 237, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\sessions.py", line 456, in request
resp = self.send(prep, **send_kwargs)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\sessions.py", line 559, in send
r = adapter.send(request, **kwargs)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\adapters.py", line 317, in send
resp = conn.urlopen(
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 491, in urlopen
httplib_response = self._make_request(conn, method, url,
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 291, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 955, in request
self._send_request(method, url, body, headers)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 989, in _send_request
self.endheaders(body)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 951, in endheaders
self._send_output(message_body)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 811, in _send_output
self.send(msg)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 773, in send
self.connect()
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\packages\urllib3\connection.py", line 197, in connect
match_hostname(self.sock.getpeercert(),
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\packages\urllib3\packages\ssl_match_hostname\_implementation.py", line 88, in match_hostname
for key, value in sub:
ValueError: too many values to unpack
所以,现在有什么方法可以在支持 pip 的 ironpython 上安装请求?我尝试使用(在管理员控制台中):
- ipy.exe -X:Frames -m pip 安装请求
- ipy.exe -X:FullFrames -m pip 安装请求
- ipy.exe -m pip 安装请求
- ipy.exe -X:Frames Scripts\pip2.7.exe 安装请求
- ipy.exe -X:FullFrames Scripts\pip2.7.exe 安装请求
- ipy.exe -X:FullFrames Scripts\pip2.exe 安装请求
- ipy.exe -X:FullFrames Scripts\easy_install-2.7.exe 请求
当我尝试 "ipy.exe -X:FullFrames -m easy_install requests" 我得到:
C:\Program Files (x86)\IronPython 2.7\Lib\weakref.py:1: DeprecationWarning: object.__init__() takes no parameters for type KeyedRef
"""Weak reference support for Python.
Searching for requests
Reading https://pypi.python.org/simple/requests/
Best match: requests 2.9.1
Downloading https://pypi.python.org/packages/source/r/requests/requests-2.9.1.tar.gz#md5=0b7f480d19012ec52bab78292efd976d
Processing requests-2.9.1.tar.gz
Writing c:\users\panta\appdata\local\temp\easy_install-mbdcgv\requests-2.9.1\setup.cfg
Running requests-2.9.1\setup.py -q bdist_egg --dist-dir c:\users\panta\appdata\local\temp\easy_install-mbdcgv\requests-2.9.1\egg-dist-tmp-rzrv6w
warning: build_py: byte-compiling is disabled, skipping.
warning: install_lib: byte-compiling is disabled, skipping.
warning: easy_install: byte-compiling is disabled, skipping.
它使用 setup.py 创建了文件夹 C:\Users\panta\AppData\Local\Temp\easy_install-mbdcgv\requests-2.9.1,但是当我尝试 运行 时,它给出了一个错误 "No commands supplied"。
那么,有一种方法可以在 ironpython 2.7.5 上导入请求吗?
编辑:现在 easy_install 它 "worked" 但是当我尝试 "import requests" 我收到以下信息:
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\__init__.py", line 53, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\__init__.py", line 27, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\urllib3\__init__.py", line 8, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\urllib3\connectionpool.py", line 34, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\urllib3\packages\six.py", line 330, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\urllib3\packages\six.py", line 320, in exec_
AttributeError: 'module' object has no attribute '_getframe'
所以,没有用于 ironpython 的请求模块?
不幸的是,urllib3
使用的 six
库(requests
使用)与 IronPython 不兼容。请参阅 six
项目跟踪器中的 issue 135,它可能有解决方法。
显然,这是阻碍 IronPython 兼容性的 唯一 问题,请参阅 requests
问题跟踪器中的 issue #2324 .
您可能可以通过将 exec_()
的定义替换为直接调用 exec()
,在 six
模块中使其工作。 urllib3
实际上并没有使用对 six.exec_()
的任何调用,并且 exec()
在 Python 2 代码中工作得很好。
我相信它至少适用于微不足道的情况。
我的确切安装命令是:
ipy.exe -X:Frames -m pip install --user requests
紧随其后的示例会话:
c:\cygwin64\home\rejap>ipy -X:Frames
IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.42000 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> r=requests.get('http://google.com')
C:\Users\rejap\AppData\Roaming\Python\IronPython27\site-packages\requests\packages\urllib3\connectionpool.py:1: DeprecationWarning: object.__new__() takes no parameters
from __future__ import absolute_import
>>> r
<Response [200]>
>>>
我已经在 ironpython 上成功安装了 pip。但是当我尝试在管理员控制台中使用 "ipy.exe -X:Frames -m pip install requests" 安装请求时,我得到以下信息:
------------------------------------------------------------
C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\__main__.py run on 02/02/16 16:13:53
Downloading/unpacking html5lib
Getting page https://pypi.python.org/simple/html5lib/
Cleaning up...
Removing temporary dir c:\users\panta\appdata\local\temp\pip_build_panta...
Exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\req.py", line 1183, in prepare_files
url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\index.py", line 194, in find_requirement
page = self._get_page(main_index_url, req)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\index.py", line 566, in _get_page
return HTMLPage.get_page(link, req,
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\index.py", line 670, in get_page
resp = session.get(url, headers={"Accept": "text/html"})
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\sessions.py", line 468, in get
return self.request('GET', url, **kwargs)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\download.py", line 237, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\sessions.py", line 456, in request
resp = self.send(prep, **send_kwargs)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\sessions.py", line 559, in send
r = adapter.send(request, **kwargs)
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\adapters.py", line 317, in send
resp = conn.urlopen(
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 491, in urlopen
httplib_response = self._make_request(conn, method, url,
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 291, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 955, in request
self._send_request(method, url, body, headers)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 989, in _send_request
self.endheaders(body)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 951, in endheaders
self._send_output(message_body)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 811, in _send_output
self.send(msg)
File "C:\Program Files (x86)\IronPython 2.7\Lib\httplib.py", line 773, in send
self.connect()
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\packages\urllib3\connection.py", line 197, in connect
match_hostname(self.sock.getpeercert(),
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\pip\_vendor\requests\packages\urllib3\packages\ssl_match_hostname\_implementation.py", line 88, in match_hostname
for key, value in sub:
ValueError: too many values to unpack
所以,现在有什么方法可以在支持 pip 的 ironpython 上安装请求?我尝试使用(在管理员控制台中):
- ipy.exe -X:Frames -m pip 安装请求
- ipy.exe -X:FullFrames -m pip 安装请求
- ipy.exe -m pip 安装请求
- ipy.exe -X:Frames Scripts\pip2.7.exe 安装请求
- ipy.exe -X:FullFrames Scripts\pip2.7.exe 安装请求
- ipy.exe -X:FullFrames Scripts\pip2.exe 安装请求
- ipy.exe -X:FullFrames Scripts\easy_install-2.7.exe 请求
当我尝试 "ipy.exe -X:FullFrames -m easy_install requests" 我得到:
C:\Program Files (x86)\IronPython 2.7\Lib\weakref.py:1: DeprecationWarning: object.__init__() takes no parameters for type KeyedRef
"""Weak reference support for Python.
Searching for requests
Reading https://pypi.python.org/simple/requests/
Best match: requests 2.9.1
Downloading https://pypi.python.org/packages/source/r/requests/requests-2.9.1.tar.gz#md5=0b7f480d19012ec52bab78292efd976d
Processing requests-2.9.1.tar.gz
Writing c:\users\panta\appdata\local\temp\easy_install-mbdcgv\requests-2.9.1\setup.cfg
Running requests-2.9.1\setup.py -q bdist_egg --dist-dir c:\users\panta\appdata\local\temp\easy_install-mbdcgv\requests-2.9.1\egg-dist-tmp-rzrv6w
warning: build_py: byte-compiling is disabled, skipping.
warning: install_lib: byte-compiling is disabled, skipping.
warning: easy_install: byte-compiling is disabled, skipping.
它使用 setup.py 创建了文件夹 C:\Users\panta\AppData\Local\Temp\easy_install-mbdcgv\requests-2.9.1,但是当我尝试 运行 时,它给出了一个错误 "No commands supplied"。 那么,有一种方法可以在 ironpython 2.7.5 上导入请求吗?
编辑:现在 easy_install 它 "worked" 但是当我尝试 "import requests" 我收到以下信息:
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\__init__.py", line 53, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\__init__.py", line 27, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\urllib3\__init__.py", line 8, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\urllib3\connectionpool.py", line 34, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\urllib3\packages\six.py", line 330, in <module>
File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\requests-2.9.1-py2.7.egg\requests\packages\urllib3\packages\six.py", line 320, in exec_
AttributeError: 'module' object has no attribute '_getframe'
所以,没有用于 ironpython 的请求模块?
不幸的是,urllib3
使用的 six
库(requests
使用)与 IronPython 不兼容。请参阅 six
项目跟踪器中的 issue 135,它可能有解决方法。
显然,这是阻碍 IronPython 兼容性的 唯一 问题,请参阅 requests
问题跟踪器中的 issue #2324 .
您可能可以通过将 exec_()
的定义替换为直接调用 exec()
,在 six
模块中使其工作。 urllib3
实际上并没有使用对 six.exec_()
的任何调用,并且 exec()
在 Python 2 代码中工作得很好。
我相信它至少适用于微不足道的情况。
我的确切安装命令是:
ipy.exe -X:Frames -m pip install --user requests
紧随其后的示例会话:
c:\cygwin64\home\rejap>ipy -X:Frames
IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.42000 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> r=requests.get('http://google.com')
C:\Users\rejap\AppData\Roaming\Python\IronPython27\site-packages\requests\packages\urllib3\connectionpool.py:1: DeprecationWarning: object.__new__() takes no parameters
from __future__ import absolute_import
>>> r
<Response [200]>
>>>