python3 global name 'SOL_SOCKET is not defined
Question: when I use `gevent`, I can not use `requests`, is my useage wrong?

    
    
    from gevent import monkey; monkey.patch_all()
    import gevent, requests
    requests.get('https://haofly.net')
    

it raise the error:

    
    
    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
    

The version of my Python is 3.3

If I add `ssl=False` to `monkey.patch_all()`, it returns:

    
    
    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
    


Answer: This is really a bug in gevent. It is trying to import a [`socket`
constant](https://docs.python.org/3/library/socket.html#constants) from the
`ssl` library.

That specific constant _happens_ to be imported into the `ssl` library because
that library makes use of it. But it is only there because a fix for [issue
19422](http://bugs.python.org/issue19422) required it to be imported in to the
`ssl` module. The fix for that bug was included in Python 3.3.4, and you have
version 3.3.3 and you thus don't have that specific constant available in the
`ssl` module as well.

You could just fix it by adding `from socket import SOL_SOCKET, SO_TYPE` in
`gevent/_ssl3.py` (located in the `/usr/local/lib/python3.3/site-packages`
directory on your system). Or you can upgrade to Python 3.3.4 or newer.

I've filed this as [issue #856](https://github.com/gevent/gevent/issues/856)
with the `gevent` project.

