Connecting to socket with authentication in python -


i'm trying connect mongodb instance through python socket. url looks this

username:password@host.com:port

how can connect python socket?

the following code gives me error: [errno -5] no address associated hostname

import socket import tornado  full_url = '%s:%s@%s' % (username, password, host) s = socket.socket() s.connect((full_url, port)) stream = iostream.iostream(s) 

edit - reason ask because asyncmongo doesn't support type of url right now. i'm trying see if can write patch. asyncmongo library connects using socket 1 in code above.

you should use driver connect mongodb. if using tornado (it looks intend so), try asyncmongo; if using threaded web server/application framework (django, pylons, etc) can use pymongo directly.


edit: why code doesn't work, socket module doesn't accept urls connection, hostname , port. low-level library. connect (web) urls, consider using urllib2 or httplib.


edit 2: authentication in mongodb not handled @ transport level, it's handled @ application level. suggest first read implementing authentication in driver, , take @ how pymongo implements authentication (in connection.py , database.py). you'll need port or reimplement mongodb connection uri parsing asyncmongo, documented here.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -