unixsnob
unixsnob

Reputation: 1705

Python _socket.socket vs socket._socketobject, how to convert from one to the other

I realised that my problem with wrapping sockets in ssl, when the socket is built from a fd is related to a socket._socketobject being converted (after rebuilding it from fd) into a socket._socket.

Is there any way to turn the socket._socket back into a _socketobject?

Thanks

Upvotes: 1

Views: 1477

Answers (1)

unixsnob
unixsnob

Reputation: 1705

The only solution that actually works was found in a lonely post here: http://www.velocityreviews.com/forums/t557014-socket-vs-_socketobject.html

To get a socket._socketobject from a socket._socket you need to do:

newSockObj = socket.socket(_sock=sock)

Ugly, but it works, as that post said...

Upvotes: 4

Related Questions