, когда я использую gevent
, я не могу использовать requests
, является ли мое использование неправильным?python3 глобальное имя 'SOL_SOCKET не определено
from gevent import monkey; monkey.patch_all()
import gevent, requests
requests.get('https://haofly.net')
это поднять ошибку:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.3/site-packages/requests/api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.3/site-packages/requests/api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.3/site-packages/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.3/site-packages/requests/sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.3/site-packages/requests/adapters.py", line 423, in send
timeout=timeout
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/connectionpool.py", line 595, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/connectionpool.py", line 352, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/connectionpool.py", line 831, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/connection.py", line 289, in connect
ssl_version=resolved_ssl_version)
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/util/ssl_.py", line 308, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/local/lib/python3.3/site-packages/gevent/_ssl3.py", line 60, in wrap_socket
_context=self)
File "/usr/local/lib/python3.3/site-packages/gevent/_ssl3.py", line 143, in __init__
if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
NameError: global name 'SOL_SOCKET' is not defined
версия моего Python является 3,3
Если добавить ssl=False
в monkey.patch_all()
, он возвращает:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.3/site-packages/requests/api.py", line 70, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.3/site-packages/requests/api.py", line 56, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.3/site-packages/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.3/site-packages/requests/sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.3/site-packages/requests/adapters.py", line 423, in send
timeout=timeout
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/connectionpool.py", line 595, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/connectionpool.py", line 352, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/connectionpool.py", line 831, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/connection.py", line 289, in connect
ssl_version=resolved_ssl_version)
File "/usr/local/lib/python3.3/site-packages/requests/packages/urllib3/util/ssl_.py", line 308, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/local/lib/python3.3/ssl.py", line 245, in wrap_socket
_context=self)
File "/usr/local/lib/python3.3/ssl.py", line 335, in __init__
server_hostname)
TypeError: _wrap_socket() argument 1 must be _socket.socket, not SSLSocket
Интересно. Это имя было бы найдено в модуле 'ssl' и импортировано. Я вижу, что Python 3.3 поддерживается; какую версию openssl вы установили? –
@MartijnPieters \t Вы имеете в виду пакет linux openssl? my openssl is openssl-1.0.1e-48.el6_8.1.x86_64, CentOS 6.8 – haofly
Проблема заключается в том, что, по-видимому, «из ssl import SOL_SOCKET» не выполняется для вашей установки. Почему это я не совсем понимаю. Возможно, у вас есть теневой модуль 'ssl'? 'import ssl; print (ssl .__ file __) 'должен печатать местоположение системы, например. –