I have a Python 3.5 script that pulls info from another Linux server. It must first connect through the 443 port to establish a connection. Unfortunately I get the following error message instead:
I can ping the Linux server but get the following error:
Traceback (most recent call last):
File "/opt/saddlesum/webapp_Py3/lib/python3.5/site- packages/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "/opt/saddlesum/webapp_Py3/lib/python3.5/site- packages/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
self._validate_conn(conn)
File "/opt/saddlesum/webapp_Py3/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn
conn.connect()
File "/opt/saddlesum/webapp_Py3/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 204, in connect
conn = self._new_conn()
File "/opt/saddlesum/webapp_Py3/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 134, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/opt/saddlesum/webapp_Py3/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 88, in create_connection
raise err
File "/opt/saddlesum/webapp_Py3/lib/python3.5/site-packages/requests/packages/urllib3/util/connection.py", line 78, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
The problem was caused by a duplicate IP address in my /etc/hosts files. Once I deleted the incorrect entry everything started working.
Hi did you finally solved this issues. I m having the same trouble.
I Set Up a wagatail app with Postgres, Nginx, and Gunicorn on Ubuntu 20. And after the the configurations, here is what I get when I send a message from the contact app.
Internal server error
Sorry, there seems to be an error. Please try again soon.
I have sentry running and telling me the errors like this:
1- ConnectionRefusedError /{var}
New Issue
Unhandled
[Errno 111] Connection refused
2 - Invalid HTTP_HOST header: '${ip}:${port}'. The domain name
Related
I'm writing an API for django & django-rest. I used to develop it on ubuntu, but when I switched to windows I've started getting these errors on every response from django.
Exception happened during processing of request from ('127.0.0.1', 54161)
Traceback (most recent call last):
File "C:\Users\Admin\anaconda3\envs\project\lib\socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\Admin\anaconda3\envs\project\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\Admin\anaconda3\envs\project\lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Users\Admin\anaconda3\envs\project\lib\site-packages\django\core\servers\basehttp.py", line 174, in handle
self.handle_one_request()
File "C:\Users\Admin\anaconda3\envs\project\lib\site-packages\django\core\servers\basehttp.py", line 182, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "C:\Users\Admin\anaconda3\envs\project\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
Developer tools also show me that this connection was cancelled. I have firewall & anti-virus programs disabled.
This is the only lin in my /etc/hosts/
127.0.0.1 localhost.localdomain localhost
I'm using windows 10.
Python 3.86
Django 3.1.2
django-cors-headers 3.5.0
djangorestframework 3.12.1
Do you know how to help this?
The issue was with the timeout on a client-side. By default some browsers set very small timeout number (1s in my case). And when server couldn't process the request aborted the connection.
I've fixed it by setting the timeout to 5s.
I'm trying to deploy code to a server to which I don't have root access. So the solution I was thinking was to deploy using pyinstaller and staticx.
My code runs in python 3.7, in a nutshell, does something like:
import requests
response = requests.get('http://example.com/api/action')
# Do something with the response
When I run it in my environment, even after "building" with pyinstaller and staticx, it works flawlessly.
However, when I try to deploy it (the server is running Red Hat Enterprise Linux Server release 7.4, which does not have python 3), I get:
Traceback (most recent call last):
File "site-packages/urllib3/connection.py", line 160, in _new_conn
File "site-packages/urllib3/util/connection.py", line 57, in create_connection
File "socket.py", line 748, in getaddrinfo
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages/urllib3/connectionpool.py", line 603, in urlopen
File "site-packages/urllib3/connectionpool.py", line 355, in _make_request
File "http/client.py", line 1229, in request
File "http/client.py", line 1275, in _send_request
File "http/client.py", line 1224, in endheaders
File "http/client.py", line 1016, in _send_output
File "http/client.py", line 956, in send
File "site-packages/urllib3/connection.py", line 183, in connect
File "site-packages/urllib3/connection.py", line 169, in _new_conn
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f912ca96f28>: Failed to establish a new connection: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages/requests/adapters.py", line 449, in send
File "site-packages/urllib3/connectionpool.py", line 641, in urlopen
File "site-packages/urllib3/util/retry.py", line 399, in increment
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='someserver.com', port=80): Max retries exceeded with url: /api/action (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f912ca96f28>: Failed to establish a new connection: [Errno -2] Name or service not known'))
Everything works if I use IP addresses instead of domains. Unfortunately, it's not a possibility because I have to hit an proxy that uses hosts. Also IP addresses may change in the future.
The server resolves names perfectly fine if I use nslookup or ping.
Any ideas why this could be happening? Any alternatives on how I could deploy my code in a way that it works in the remote server may also be a valid answer. Note however:
I have no root access and requesting the installation of python3, any libs or any other package such as docker, etc would most likely be rejected by my customer
The server can resolve external names, such as google.com but does not have access to the outer internet (the code is ment to work on internal servers, with internal DNS such as someserver.mycustomer.example)
I want to establish a FTP connection to Windows server (let's say 10.20.30.50)
I am using Python ftblib package
session = ftplib.FTP('10.20.30.40','admin','password#123')
file = open('download.jpg','rb') # file to send
session.storbinary('STOR download.jpg', file) # send the file
file.close() # close file and FTP
session.quit()
But I am getting the error
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\ftplib.py", line 120, in __init__
self.connect(host)
File "C:\Python27\lib\ftplib.py", line 135, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout)
File "C:\Python27\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it.
I tried telnet 10.20.30.40 8081 and it is successful.
I allow port 8081 for ftp. I open port by adding new inbound rules.
I tried several available solutions on Stack Overflow as well as other sites but they all are talking about to check the port. I do all the things but still no help.
Thanks
If your FTP server uses a non-standard port (8081), you have to specify that, when using FTP class.
session = ftplib.FTP()
session.connect('10.20.30.40', 8081)
session.login('admin','password#123')
See also Python ftplib - specify port.
I forgot to enable FTP service in server. I followed this link and it is solved my issue
https://medium.com/#JohGeoCoder/allowing-ftp-access-on-windows-server-2016-hosted-on-microsoft-azure-af25898df958
I have created a python script connecting to a Phoenix HBase to analyze some data. I want to set this script up on crontab on a ubuntu server that I have running.
The script is perfectly able to run on my Windows 10 machine. But when I try to use the phoenixdb connector on Ubuntu I get an error on RunTime.
>>> import phoenixdb
>>> url = '<some-url>'
>>> conn = phoenixdb.connect(url, autocommit=True)
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.5/site-packages/phoenixdb/avatica.py", line 156, in connect
self.connection.connect()
File "/usr/lib/python3.5/http/client.py", line 849, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/lib/python3.5/socket.py", line 711, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 702, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/.local/lib/python3.5/site-packages/phoenixdb/__init__.py", line 63, in connect
client.connect()
File "/home/ubuntu/.local/lib/python3.5/site-packages/phoenixdb/avatica.py", line 158, in connect
raise errors.InterfaceError('Unable to connect to the specified service', e)
phoenixdb.errors.InterfaceError: ('Unable to connect to the specified service', TimeoutError(110, 'Connection timed out'), None, None)
I was hoping someone here knows a way to fix this problem?
I am running Python 3.6 on Windows and Python 3.5.2 on Ubuntu, but I doubt that that is the problem.
EDIT:
I have now started a Windows 2012 Server and have tried setting my script up here as well, and it seems not to be a problem solely for Ubuntu. I am getting the exact same error on Windows.
>>> import phoenixdb
>>> url = '<some-url>'
>>> conn = phoenixdb.connect(url, autocommit=True)
Traceback (most recent call last):
File "C:\Users\Administrator\Anaconda3\lib\site-packages\phoenixdb\avatica.py", line 156, in connect
self.connection.connect()
File "C:\Users\Administrator\Anaconda3\lib\http\client.py", line 936, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Users\Administrator\Anaconda3\lib\socket.py", line 722, in create_connection raise err
File "C:\Users\Administrator\Anaconda3\lib\socket.py", line 713, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Administrator\Anaconda3\lib\site-packages\phoenixdb\__init__.py", line 63, in connect
client.connect()
File "C:\Users\Administrator\Anaconda3\lib\site-packages\phoenixdb\avatica.py", line 158, in connect
raise errors.InterfaceError('Unable to connect to the specified service', e)
phoenixdb.errors.InterfaceError: ('Unable to connect to the specified service',
TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None), None, None)
I recently did format the PC that I developed the script on. The was using this phoenixdb connector, and I did not experience a similar problem on that.
I did also try to install Python 3.6 on the Windows machine (similar to the same python version that I installed on my normal PC - the one I developed the script on).
I'm really lost for finding a solution..
I finally found the problem. It had nothing to do with the machines I set up my script on. It had to do with security settings on the AWS Machines that both the Ubuntu and Windows Servers were.
My goal is to have a basic FTP program written in Python. First, I need to gain more knowledge. My question is, how can I connect to an Ubuntu Server (hosted via VirtualBox) using Python?
I have tried using the page on the official Python website but I get an error saying socket.error: [Errno 61] Connection refused when using this
from ftplib import FTP
ftp = FTP('jordan#10.0.0.12')
This is the output I get when using ftp - FTP('10.0.0.12')
Traceback (most recent call last): File "", line 1, in
File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ftplib.py",
line 120, in init
self.connect(host) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ftplib.py",
line 135, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout) File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py",
line 575, in create_connection
raise err socket.error: [Errno 61] Connection refused
I can use an FTP program such as Transmit (the same port and on SFTP) on the same machine and it works fine.
Python's ftplib does not support SFTP, so using PySFTP would work.
An alternative is using paramiko.