Not able to authenticate Askbot django application on Ubantu 18.04
Able to ping the LDAP server, but still it says - "Can't contact LDAP server"
Error logs shows:-
Traceback (most recent call last): File
"/srv/askbot/venv/local/lib/python2.7/site-packages/askbot/deps/django_authopenid/ldap_auth.py",
line 127, in ldap_authenticate_default
get_attrs File "/srv/askbot/venv/local/lib/python2.7/site-packages/ldap/ldapobject.py",
line 854, in search_s
return self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout=self.timeout)
File
"/srv/askbot/venv/local/lib/python2.7/site-packages/ldap/ldapobject.py",
line 847, in search_ext_s
msgid = self.search_ext(base,scope,filterstr,attrlist,attrsonly,serverctrls,clientctrls,timeout,sizelimit)
File
"/srv/askbot/venv/local/lib/python2.7/site-packages/ldap/ldapobject.py",
line 843, in search_ext
timeout,sizelimit, File "/srv/askbot/venv/local/lib/python2.7/site-packages/ldap/ldapobject.py",
line 331, in _ldap_call
reraise(exc_type, exc_value, exc_traceback) File "/srv/askbot/venv/local/lib/python2.7/site-packages/ldap/ldapobject.py",
line 315, in _ldap_call
result = func(*args,**kwargs) SERVER_DOWN: {u'info': 'Transport endpoint is not connected', 'errno': 107, 'desc': u"Can't contact LDAP
server"}
Ping uses the ICMP protocol. LDAP uses a TCP connection to (usually) port 389 (or 636 for LDAPS). Those are two different things.
So the fact that you can ping the server only means the server is online. It doesn't mean that the LDAP service is running or that a firewall is not blocking TCP traffic to the right port.
You can test opening a TCP connection to the right port on Ubuntu in one of two ways:
telnet yourserver 389
Or,
nmap yourserver 389
More information on that here.
You may have to install telnet or nmap for those to work. And if you're using LDAPS (LDAP over SSL) then you should test port 636.
Related
How do I connect to remote docker host using python?
>>> from docker import Client
>>> cli = Client(base_url='tcp://52.90.216.176:2375')
>>>
>>> cli.containers()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/docker/api/container.py", line 69, in containers
res = self._result(self._get(u, params=params), True)
File "/usr/local/lib/python2.7/site-packages/docker/utils/decorators.py", line 47, in inner
return f(self, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/docker/client.py", line 112, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 480, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 437, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='52.90.216.176', port=2375): Max retries exceeded with url: /v1.21/containers/json?all=0&limit=-1&trunc_cmd=0&size=0 (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7fd87d836750>: Failed to establish a new connection: [Errno 111] Connection refused',))
If I log-in to 52.90.216.176 and use the following:
>>> cli = Client(base_url='unix://var/run/docker.sock')
this works. But how do I connect to docker running on another server?
It sounds like you're using docker-py.
Also, it sounds like maybe you're not familiar with TLS, so please read the documentation for using TLS with docker-py. You may need to download your TLS files and copy them local to the docker-py client as they are used to authenticate that you are authorized to connect to the Docker daemon.
I hope your remote Docker daemon is not exposed to the world.
If it is not running TLS (exposed to the world):
client = docker.Client(base_url='<https_url>', tls=False)
If it is secured with TLS (not exposed to the world):
client = docker.Client(base_url='<https_url>', tls=True)
This is not answer, but need your feedback.
The error message is: Connection refused, so can you run the command:
telnet 52.90.216.176 2375
To confirm if there is no firewall issue. Sometime the port is 2376
Add tcp option to sys config as shown here:
vi /etc/sysconfig/docker
OPTIONS="--host=tcp://0.0.0.0:2375"
After restarting docker, I could connect to remote docker server using python.
I'm with a very very wierd bug...
I have a flask app using flask-mail to send email messages.
In a RedHat Server, I tryied using runserver (flask-manager) and gunicorn. So I have a apache server connecting to this app using Proxy.
When I run the app, using any user (root or other), the app runs and it sends emails normally.
But when i close the session with the server (exit in terminal) it stops to send mail and gives me this stack trace:
in send_mail
return mail.send(msg)
File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 415, in send
with self.connect() as connection:
File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 123, in __enter__
self.host = self.configure_host()
File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 144, in configure_host
host.login(self.mail.username, self.mail.password)
File "/usr/local/lib/python2.7/smtplib.py", line 575, in login
self.ehlo_or_helo_if_needed()
File "/usr/local/lib/python2.7/smtplib.py", line 535, in ehlo_or_helo_if_needed
if not (200 <= self.ehlo()[0] <= 299):
File "/usr/local/lib/python2.7/smtplib.py", line 406, in ehlo
self.putcmd(self.ehlo_msg, name or self.local_hostname)
File "/usr/local/lib/python2.7/smtplib.py", line 336, in putcmd
self.send(str)
File "/usr/local/lib/python2.7/smtplib.py", line 320, in send
print>>stderr, 'send:', repr(str)
IOError: [Errno 5] Input/output error
Running with manager:
python myapp.py
Running with gunicorn I use:
gunicorn -w 2 -b 0.0.0.0:8388 myapp:app
I'm really stuck here.. as i tested using 2 different containers... i do not have any other ideias to solve it... using wsgi i could not make it work on this server cause the lib do not install at all =(
any other ideas?
thanks!
Looking at smtplib source (https://hg.python.org/cpython/file/2.7/Lib/smtplib.py#l324), it looks like what's happening is you're trying to write to stderr, which may be the source of the I/O error when running under a server.
If you're setting SMTP(...).debuglevel anywhere, try removing that line.
So I have two AWS servers in question, one is running MariaDB and the other is my API server (python based). I can connect just fine locally on the MariaDB server as well as my dev computer. I cannot connect from the API server nor a third AWS server.
netstat output
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:mysql *:* LISTEN 1363/mysqld
ngrep on API server shows
interface: eth0 (10.[api ip]/255.255.255.0)
filter: (ip or ip6) and ( port 3306 )
##########
ngrep on Maria Server
interface: eth0 ([maria ip]/255.255.255.0)
filter: (ip or ip6) and ( port 3306 )
####
T [maria ip]:3306 -> [dev ip]:2392 [AP]
[redacted]
##
T [dev ip]:2392 -> [maria ip]:3306 [AP]
[redacted]
##
T [maria ip]:3306 -> [dev ip]:2392 [AP]
[redacted]
#######################
Eventually I get this error
ERROR 2003 (HY000): Can't connect to MySQL server on '[maria ip]' (110 "Connection timed out")
or from my python script
Exception happened during processing of request from ('127.0.0.1', 50110)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 651, in __init__
self.finish()
File "/usr/lib/python2.7/SocketServer.py", line 710, in finish
self.wfile.close()
File "/usr/lib/python2.7/socket.py", line 279, in close
self.flush()
File "/usr/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------
Before somebody mentions it, my IP tables are set correctly and AWS SecGrps are not the issue either.
This is not a duplicate of Trying to connect to remote MySQL host (error 2003) as (1) there are no (logical) devices between the server, (2) I can connect from my Dev station on the other side of the country, and (3) none of the "fixes" worked.
Also I can connect from API script to Redis Server running on my maria server.
I think you have to follow these steps as below:
Allow remote connect on MariaDB AWS server on 3306 port (depend on your config)
Check the Firewall (Security Group --> Inbound setting) on your Maria AWS server, this server have to allow access via 3306 port from IP address of API Server.
Check the Firewall (Security Group --> Oubound setting. By default AWS server allow all ports) on your API AWS server.
Reference # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html
I've been trying to connect to my Gmail account using python. imap is enabled.
import imaplib
imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
# also tried imap_server = imaplib.IMAP4_SSL("imap.gmail.com"), doesnt work.
Traceback is :
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 1202, in __init__
IMAP4.__init__(self, host, port)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 172, in __init__
self.open(host, port)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 1217, in open
IMAP4.open(self, host, port)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 248, in open
self.sock = self._create_socket()
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 1205, in _create_socket
sock = IMAP4._create_socket(self)
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/imaplib.py", line 238, in _create_socket
return socket.create_connection((self.host, self.port))
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socket.py", line 435, in create_connection
raise err
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socket.py", line 426, in create_connection
sock.connect(sa)
OSError: [Errno 65] No route to host
What OSError: [Errno 65] No route to host means is what it say: you can't get to that machine from your machine.
You can test that from outside of Python by opening up a terminal/DOS prompt and typing this:
ping imap.gmail.com
It's possible that this is actually a name lookup error, and you're somehow getting a bad address for imap.gmail.com. So, just to be sure, check by IP address too:
ping 74.125.129.108
ping 74.125.129.109
If ping works, you can check whether your router is for some reason just blocking TCP access to the host, e.g., with:
telnet imap.gmail.com
If it's working, this should either hang for a long time, or give you a connection-refused error; if it gives you a no-route-to-host error, it's the same problem you're seeing.
It's also possible that your router is specifically blocking port 993. You can test this too:
telnet imap.gmail.com 993
If it doesn't come back with something like "Connected to gmail-imap.l.google.com", same problem here too.
At any rate, once you've verified that this is a system or network configuration problem, not a programming problem, go ask for help with your system on the appropriate site.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Django - [Errno 111] Connection refused
I have found a a link on how to send email with django : https://docs.djangoproject.com/en/dev/topics/email/
i followed the example and i got this:
>>> from django.core.mail import send_mail
>>> send_mail('dfdf', 'dfdfdf', 'logadrinab#agile.com.ph', ['ddcahanap#agile.com.ph'])
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/__init__.py", line 61, in send_mail
connection=connection).send()
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 251, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 79, in send_messages
new_conn_created = self.open()
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 42, in open
local_hostname=DNS_NAME.get_fqdn())
File "/usr/lib/python2.7/smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 111] Connection refused
>>>
i think it's because of EMAIL_HOST and EMAIL_PORT, if it is so
where can I find it and how to use it? If it is not can anyone give me an idea on how to send email in django?
thanks in advance...
In your settings.py for your project, make sure you set your EMAIL_HOST, EMAIL_PORT and other settings (like a username or password if your host requires authentication).
Also, make sure you are running the console using the manage.py shell command, and not your normal python shell, so django loads the settings correctly.
You are getting an error because you have no mail transfer agent installed on you system.
You just need to install postfix package in default configuration (it will ask you some questions during install, just choose defaults).
And there is no need to altering your configuration or settings.py or whatever.
You'll need to correctly configure the SMTP email backend for your current host and test it interactively like you just did.
It's possible that they're using TLS or an alternate port--you should look it up in your account settings. Alternatively you can configure Django to use a remote service host, like Gmail, to get yourself started if you have no other options.
You are right, you need to specify correct host and port in settings.py.
What server you are going to use? If it is your hosting provider's server, for example, it is better to contact hosting support to get this info.