I'm trying to connect to a mongodb instance through a python socket. The url looks like this
username:password#host.com:port
how can I connect to this with a python socket?
The following code gives me this error: [Errno -5] No address associated with 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 - the reason I ask is because asyncmongo doesn't support this type of url right now. I'm trying to see if I can write a patch. The asyncmongo library connects using a socket like the one in the code above.
You should use a driver to connect to mongodb. If you are using Tornado (it looks like you intend to do so), try asyncmongo; if you are using a threaded web server/application framework (Django, Pylons, etc) you can use PyMongo directly.
Edit: As for why this code doesn't work, the socket module doesn't accept URLs for connection, just hostname and port. It is a low-level library. To connect to (web) urls, consider using urllib2 or httplib.
Edit 2: Authentication in MongoDB is not handled at the transport level, it's handled at the application level. I suggest you first read Implementing Authentication in a Driver, and then take a look at how PyMongo implements authentication (in connection.py and database.py). You'll also need to port or reimplement the MongoDB connection URI parsing for asyncmongo, which is documented here.
Related
I am in the process of building a custom authentication for email accounts. The imap/pop3 server is dovecot. The dovecout have an easy option to use Key-value authentication (dict) database via socket. The have the documentation and perl socket server example in https://doc.dovecot.org/configuration_manual/authentication/dict/
I need a socket server in python to enable authentication via socket url
uri = proxy:/var/run/auth_proxy_dovecot/socket:somewhere
What inputs are need to send the socket?
What is the format of the input ?
What are the output format expected ?
I was unable to find any such developer documentations regarding it .
The only documentation they say is it use the protocol https://github.com/dovecot/core/blob/master/src/lib-dict/dict-client.h
I understand it is a simple script , but if some one wrote such python script or socket program , it will be good to know where to find those documentations.
I wrote a python server using the socketserver class To read data from the socket and process it.
I am using the following script to get issues from Jira.
from jira import JIRA
options = {'server': 'https://it.company.com/'}
jira = JIRA(options, basic_auth=('user', 'password'), max_retries=1)
issues = jira.search_issues('project="Web"', startAt=0, maxResults=50)
I want to replace https://it.company.com/ with https://ip:port.
I usedping to get the IP.
I used nmap for checking ports, but no matter what https://ip:port input I use, I can't get a connection. I also tried these ports.
How can I find out which IP and Port is JIRA() accessing?
The https protocol uses port 443. Refer to wikipedia for details.
However accessing a server via https://server_name/ is different from accessing a server via https://server_ip_address/. This is because during TLS negotiation, server_name is passed to the server via TLS SNI (Server Name Indication). This way multiple virtual websites may be hosted at the same server_ip_address. See wikipedia for details.
If the script works and you just want to know how the connection looks, I recommend letting it run and in the background execute netstat -ano.
If the script doesn't work and you just want to know where it tries to connect, I recommend installing wireshark.
Edit: In any case you (most likely) won't be able to replace it with ip:port because servers treat HTTP requests to an IP different than how they treat requests to a name.
Ask the Jira admin to tell you. Configured in conf/server.xml like any Tomcat app, or there may be a remote proxy such as nginx configured in front of the Jira
I have been using parse as my project server and now that I have migrated the data to local server, successfully made dashboard work; but I cannot find a way to access api.parse.com/1/ API.
I used to use python to make REST requests and it is basically establishes socket connection with api.parse.com at port 443. Now I am trying to connect to localhost at port 1337 which is where the parse-server instance is running. However, I have not been able to access the API same as before.
One thing to note is that I can successfully curl to get basic JSON response from requests like
curl -X GET -H ... http://localhost:1337/parse/classes/_User
The question is which connection now replaces api.parse.com for locally held parse-server instances?
Ahh I found out the answer:
You make socket connection with address and port where the parse-server is running, and then instead of doing
conn.request("GET", "/1/login?%s"%...)
You do:
conn.request("GET", "/parse/login?%s"%...)
Hope this helps.
db = MySQLdb.connect(host ="host",
user="user",
passwd="pass",
db="dbname")
q = db.cursor()
So, that's my code block, I was just wondering, how easy would this be to reverse engineer, and does mysqldb send authentications over cleartext?
I am creating a program that connects to a mySQL server over the internet, would someone be able to get my credentials?
Would someone be able to get my server login details?
The MySQL server could be configured to use SSL to secure the connection. See here for an example of using MySQLdb with an SSL connection and here for some info on configuring the server.
In your example above the username, password and all other data would be sent in cleartext.
Here are two related questions Python MySQLDB SSL Connection , CA SSL parameter for Python MySQLdb not working, but key does?
If you have access to change configure the MySQL server, we can help configure SSL.
MySQL supports encrypted connections. The MySQL server you are connecting to must be configured to use SSL and the client must add an SSL parameter when connecting.
Using SSL connections
shell> mysql --ssl-ca=ca-cert.pem ...
You can test if the server you are connecting to supports SSL my adding --ssl-ca=ca-cert.pem.
ca-cert.pem: Use this as the argument to --ssl-ca on the server and client sides. (The CA certificate, if used, must be the same on both sides.)
MySQL SSL Example describes the process from setting up MySQL for and connecting with SSL.
Passwords shouldn't be hardcoded in the code. Python has the convention of a config.py module, where you can keep such values separate from the rest of your code.
Please have a look here:
http://dev.mysql.com/doc/refman/5.5/en/connector-python-coding.html
The question regarding SSL to prevent disclosure has been answered above.
Fabio
#fcerullo
i'm trying to connect my local XMPP server by the code coming below
import xmpp
client = xmpp.Client('localhost',debug=[])
client.connect(server=('localhost',5222))
but i always get this message :
An error occurred while looking up _xmpp-client._tcp.localhost
i've checked that the port 5222 is already opened(by using telnet).
(i have to mention that the firewall on the localhost is off)
now what should i add to this code to make it work ?
This message (a warning, not an error as pointed out in xinox's answer) is indicating that a DNS SRV record lookup failed. DNS SRV records are used to find services that are associated with a certain domain (eg. localhost in this case, so not really a domain at all which is why the lookup is failing), but which delegate their responsibility to a server living somewhere else.
For instance, if I have a server at example.net, making my Jabber ID (JID): user#example.net, but my XMPP server lived at chat.example.net I could construct an SRV record on example.net to point to chat.example.net. There are other ways to delegate responsibility, but this is the preferred one. XMPPs use of SRV records is defined in RFC 6120 ยง3.2.1.
To actually get rid of this error you can use the use_srv kwarg, making your initial example:
import xmpp
client = xmpp.Client('localhost',debug=[])
client.connect(server=('localhost',5222), use_srv=False)
use this.
client = xmpp.Client('127.0.0.1',debug=[])
client.connect(server=('127.0.0.1',5222))
or your IP 192.X.X.X