https:// urlμ μμ²ν λ request
λ©μλλ 무ν μ¬κ·μ λΉ μ§λ€.
λ¬Έμ λ python/ssl.py
μ΄ λ°©λ²μ
λλ€.
@options.setter
def options(self, value):
super(SSLContext, SSLContext).options.__set__(self, value)
μ΄ λΌμΈμ νμ΄μ¬μ λμ ν 컀λ°μ https://hg.python.org/cpython/rev/c32e9f9b00f7μ λλ€.
μ€μ μ€λ₯λ λ€μκ³Ό κ°μ΅λλ€.
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 501, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 423, in send
timeout=timeout
File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 594, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 350, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 835, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/connection.py", line 311, in connect
cert_reqs=resolve_cert_reqs(self.cert_reqs),
File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/util/ssl_.py", line 264, in create_urllib3_context
context.options |= options
File "/usr/local/lib/python3.6/ssl.py", line 459, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.6/ssl.py", line 459, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.6/ssl.py", line 459, in options
super(SSLContext, SSLContext).options.__set__(self, value)
[Previous line repeated 316 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
python 3.6.0b4
μ¬μ©νμ¬ ν
μ€νΈνμ΅λλ€.
μ΄κ²μ νμ€ λΌμ΄λΈλ¬λ¦¬μ λ²κ·ΈμΈ κ²μ²λΌ λ€λ¦¬μ§λ§ μ€μ λ‘λ μ΅μ μ μ§μ μ€μ ν λ 무ν μ¬κ·λ₯Ό λμ ν κ² κ°μ΅λλ€. @ν°λ?
λ΄ μ»΄ν¨ν°μμ λ¬Έμ λ₯Ό μ¬νν μ μμ΅λλ€(μ΅μ hg 3.6 λΆκΈ°μ Python).
$ ./python
Python 3.6.0+ (3.6:c4f39b6f3176, Dec 7 2016, 21:55:50)
[GCC 6.2.1 20160916 (Red Hat 6.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ctx = ssl.SSLContext(ssl.PROTOCOL_TLS)
>>> ctx.options |= 5
>>> class MySSLContext(ssl.SSLContext):
... pass
...
>>> ctx = MySSLContext(ssl.PROTOCOL_TLS)
>>> ctx.options |= 5
λλ μμ² λμμ κ·Έκ²μ μ¬ννλ €κ³ μλνμ΅λλ€. 3.6.0b4 λλ 3.6.0rc1μμ μΉ μ μμ΅λλ€.
$ python
Python 3.6.0b4 (v3.6.0b4:18496abdb3d5, Nov 21 2016, 20:44:47)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get('https://github.com/kennethreitz/requests/issues/3752')
<Response [200]>
$ python
Python 3.6.0rc1 (v3.6.0rc1:29a273eee9a5, Dec 6 2016, 16:24:13)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get('https://github.com/kennethreitz/requests/issues/3752')
<Response [200]>
νλ«νΌμ΄λ URLμ λ°λΌ λ€λ₯Ό μ μμ΅λκΉ?
(OS X 10.12.1, 16B2659, μ κ²½μ°)
μμ²μ hgμ Python 3.6.0μμλ μλν©λλ€.
$ ./python -m venv venv
$ venv/bin/pip install requests
Collecting requests
Using cached requests-2.12.3-py2.py3-none-any.whl
Installing collected packages: requests
Successfully installed requests-2.12.3
$ venv/bin/python
Python 3.6.0+ (3.6:c4f39b6f3176, Dec 7 2016, 21:55:50)
[GCC 6.2.1 20160916 (Red Hat 6.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get('https://www.python.org')
<Response [200]>
μ, μ§κΈμ "볡μ ν μ μλ" μν©μ²λΌ 보μ λλ€. μ€μΉ @juokaz λ₯Ό λ³Ό κ°μΉκ° μμ μ μμ΅λλ€. μ½κ° μ€μλνλ κ² κ°μ΅λλ€.
μΆκ° λλ²κΉ
νμ gevent
λ¬Έμ λ‘ μ¬νν μ μμμ΅λλ€(μ΄λ λ΄κ° μ΄κ²μ μ¬μ©νλ 컨ν
μ€νΈμμ΅λλ€).
μ μκ°μ gevent μ¬λλ€μ΄ 보기 μν΄ κ°μ Έκ°μΌ ν κ² κ°μλ°μ? μ‘°μ¬ν΄ μ£Όμ μ κ°μ¬ν©λλ€.
root<strong i="8">@8042e3f57981</strong>:/app# python
Python 3.6.0b4 (default, Nov 23 2016, 21:34:29)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gevent.monkey
>>> gevent.monkey.patch_all()
>>>
>>> from requests.packages.urllib3.util.ssl_ import create_urllib3_context
>>> create_urllib3_context()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/requests/packages/urllib3/util/ssl_.py", line 268, in create_urllib3_context
context.options |= options
File "/usr/local/lib/python3.6/ssl.py", line 459, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.6/ssl.py", line 459, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "/usr/local/lib/python3.6/ssl.py", line 459, in options
super(SSLContext, SSLContext).options.__set__(self, value)
[Previous line repeated 329 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
>>>
μ, μ΄κ²μ gevent λ¬Έμ μ λλ€. λλ geventκ° μμ§ Python 3.6μμ μλνμ§ μλλ€κ³ κ°μ ν©λλ€.
super() νΈμΆμ΄ μ΄μν΄ λ³΄μ΄μ§λ§ λ§μ΅λλ€. λΆλͺ¨ ν΄λμ€μ μμ± μ€λͺ μλ₯Ό κ°μ Έμ€λ μΌλ°μ μΈ λ°©λ²μ λλ€. νμ ν΄λμ€μμ μμ±μ λ³κ²½νλ κ²μ νμμ μ λλ€. Googleμ "David Beazley νμ ν΄λμ€ μμ±"μ μμ²νλ©΄ λμΌν λ΄μ©μ΄ νμλ©λλ€( https://www.safaribooksonline.com/library/view/python-cookbook-3rd/9781449357337/ch08s08.html).
>>> from ssl import SSLContext
>>> super(SSLContext, SSLContext).options
<attribute 'options' of '_ssl._SSLContext' objects>
>>> import _ssl
>>> super(SSLContext, SSLContext).options is _ssl._SSLContext.options
True
super(SSLContext, SSLContext).options.__set__(self, value)
νΈμΆμ λΆλͺ¨ ν΄λμ€μ μΈμ€ν΄μ€μ μ΅μ
μ μ€μ νλ κ²κ³Ό κ°μ΅λλ€.
λ€μμ λμΌν λ¬Έμ μ λν gevent ν°μΌμ λν μ°Έμ‘°μ
λλ€. https://github.com/gevent/gevent/issues/903
μ΄μ Geventλ κΈ°λ³Έμ μΌλ‘ >1.2λ‘ μΆ©λνμ΅λλ€. μ΄ λ¬Έμ κ° κ³μ λ°μνλ©΄ κ°λ¨ν pip install --upgrade gevent
ν΄κ²°ν μ μμ΅λλ€.
λλ₯Ό μν΄ λ¬Έμ λ₯Ό ν΄κ²°νμ§ μλ @pirate . λ€λ₯Έ μμ΄λμ΄κ° μμ΅λκΉ? λ€λ₯Έ μ€λ λκ° μ 겨 μμ΅λλ€.
@AeroNotix μ΄ λ¬Έμ λ μ΄ νλ‘μ νΈμ νΈλ컀λ₯Ό μ¬μ©νμ¬ gevent λ¬Έμ λ₯Ό λ Όμνμ§ λ§μμμ€.
@pirate κ·ΈλΌ κ·Έ ν°μΌμ μ κΈ ν΄μ ν μ μλμ? λλ μ¬μ ν λͺ¨λ κ²μ΄ μ κ·Έλ μ΄λ λ λ²μ μΌλ‘ python 3.6μμ λμΌν λ¬Έμ λ₯Ό κ²ͺκ³ μμ΅λλ€.
μλμ @AeroNotix , μ λ λ νλ‘μ νΈμ κΈ°μ¬μκ° μλλλ€. λ€λ₯Έ μ€λ λμ μλ μ¬λ μ€ ν λͺ μκ² μ§μ μ΄λ©μΌ/IRCλ₯Ό λ³΄λΌ μ μμ΅λκΉ?
@pirata μ΄ λ¬Έμ λ python 3.6.1
, gevent 1.2.1
, requests 2.13.0
μ¬μ ν μ‘΄μ¬ν©λλ€. μ¬ν λ¨κ³:
import requests
import gevent.monkey
gevent.monkey.patch_ssl()
requests.get("https://google.com")
ν¨μΉ ν requests
κ°μ Έμ€λ©΄ λͺ¨λ κ²μ΄ μλν©λλ€. μμ μλ μκ΄μμ μ λμλλ° μμ νλμ μ μ§νκΈ° μν΄ λκ°λ₯Ό λ°κΏ μ μλμ§ κΆκΈν©λλ€. @Lukasa μ΄λ»κ² μκ°
μμ²μ κ°μ Έμ¬ λ μ ν λͺ¨λμμ κΈ°λ₯ κ°μ§λ₯Ό μννκΈ° λλ¬Έμ gevent λ° monkey ν¨μΉμ λͺ κ°μ§ λ¬Έμ κ° μμ΅λλ€. ν₯ν 릴리μ€μμλ μ΄ λ¬Έμ μ λν μμ μ¬νμ΄ ν¬ν¨λ μ΅μ urllib3λ‘ μ λ°μ΄νΈν μμ μ΄μ§λ§ κ·Έ λμ μμ²μ κ°μ Έμ€κΈ° μ μ geventμ μμμ΄ ν¨μΉλ₯Ό μ μ©ν΄μΌ ν©λλ€.
@Lukasa μ΄λ² λ¦΄λ¦¬μ€ λ₯Ό λ§μνμλ 건κ°μ?
κ°μ₯ μ μ©ν λκΈ
μμ²μ κ°μ Έμ¬ λ μ ν λͺ¨λμμ κΈ°λ₯ κ°μ§λ₯Ό μννκΈ° λλ¬Έμ gevent λ° monkey ν¨μΉμ λͺ κ°μ§ λ¬Έμ κ° μμ΅λλ€. ν₯ν 릴리μ€μμλ μ΄ λ¬Έμ μ λν μμ μ¬νμ΄ ν¬ν¨λ μ΅μ urllib3λ‘ μ λ°μ΄νΈν μμ μ΄μ§λ§ κ·Έ λμ μμ²μ κ°μ Έμ€κΈ° μ μ geventμ μμμ΄ ν¨μΉλ₯Ό μ μ©ν΄μΌ ν©λλ€.