Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3: socket._fileobject removed #434

Closed
buhman opened this issue Sep 3, 2013 · 14 comments
Closed

python3: socket._fileobject removed #434

buhman opened this issue Sep 3, 2013 · 14 comments

Comments

@buhman
Copy link

buhman commented Sep 3, 2013

testcase:

#!/usr/bin/env python3

from werkzeug.serving import run_simple
from OpenSSL import SSL

def hello(env, res):
    res(b'200 OK', [(b'Content-Type', b'text/html')])
    return [b'hello\n']

context = SSL.Context(SSL.TLSv1_METHOD)
context.use_privatekey_file('key.pem')
context.use_certificate_file('cert.pem')

run_simple('localhost', 5000, hello, 
           use_reloader=True, ssl_context=context)

First, you'll need to (trivially) work around pyopenssl's LP#1211834 (2to3 OpenSSL/tsafe.py).

If you simply 'curl https://localhost:5000':

Exception happened during processing of request from ('127.0.0.1', 57812)
Traceback (most recent call last):
  File "/usr/lib/python3.3/socketserver.py", line 306, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.3/socketserver.py", line 332, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.3/socketserver.py", line 345, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.3/socketserver.py", line 664, in __init__
    self.setup()
  File "/usr/lib/python3.3/socketserver.py", line 716, in setup
    self.rfile = self.connection.makefile('rb', self.rbufsize)
  File "/usr/lib/python3.3/site-packages/werkzeug/serving.py", line 368, in makefile
    return socket._fileobject(self._con, mode, bufsize)
AttributeError: 'module' object has no attribute '_fileobject'

I'd also noticed OpenSSL.SSL.Connection.makefile() is unimplemented, which is presumably the entire purpose of werkzeug.serving._SSLConnectionFix

@thehesiod
Copy link

hit the same thing

@redtoad
Copy link

redtoad commented Oct 15, 2013

same problem here

@depassp
Copy link

depassp commented Dec 20, 2013

Having the same problem.

@datagrid
Copy link

+1

1 similar comment
@dgelvin
Copy link

dgelvin commented Jul 7, 2014

+1

@homeworkprod
Copy link
Contributor

Yes, please work on fixing this.

Ran through a sequence of issues, fixed them myself (and discovered the – yet unreleased – fixes later on in the respective projects: 0bad0c2, 6e5591c, pyca/pyopenssl@65627a2), but gave up after unsuccessfully attempting to use socket.SocketIO instead of socket._fileobject.

I was using Python 3.4 and PyOpenSSL 0.14.

@thehesiod
Copy link

I've given up and succesfully switched to tornado.

@asakharov
Copy link

+1
Please, support python 3

@untitaker
Copy link
Contributor

Awesome, now I have this problem too, but have enough experience in order to know that this won't get fixed soon.

@DasIch
Copy link
Contributor

DasIch commented Aug 21, 2014

Sorry to hear that, though now that you presumably have some motivation you might be able to figure out a good way to fix it ;)

The socket module in Python 3 has changed substantially which makes fixing this quite difficult. As you shouldn't use this in production anyway I think it might make sense to consider dropping this and recommending to use gunicorn, which afaik supports SSL.

@untitaker
Copy link
Contributor

I'm not sure, I think it's useful. #454 actually presents a solution to this.

@untitaker
Copy link
Contributor

For context, i use this in pimutils/vdirsyncer#106

@untitaker
Copy link
Contributor

This is now fixed in #565 and will most likely be included in 0.10. Please note there are some API changes on advanced SSL usage.

@Ivoz
Copy link

Ivoz commented Aug 30, 2014

👏 @untitaker

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests