Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am running a program built on Python. When I am running the program on the Wintel server via port 80 I have no issues. Program name - TelegramBot-ASN.py.
Port 80
Running on http://<IP Address>:80/ (Press CTRL+C to quit)
However via port 443 encounter below issue
Traceback (most recent call last):
File "TelegramBot-ASN.py", line 49, in <module>
app.run(host=strHost, port=strPort, debug=True)
File "C:\RPA\Applications\Python\lib\site-packages\flask\app.py", line 990, in run
run_simple(host, port, self, **options)
File "C:\RPA\Applications\Python\lib\site-packages\werkzeug\serving.py", line 987, in run_simple
s.bind(server_address)
socket.gaierror: [Errno 11001] getaddrinfo failed
After studying the error a little, it is seen that the error was thrown while trying to bind the socket.
Usually, a common error in a bind is that the port to be used is already used.
But here is the getaddrinfo failed error.
If you are not given an IP for the host argument in the app.run method, give an IP. (internetwork IP).
Do not give domain names like localhost.
Example : app.run(host="192.168.1.102",
Also find out if 443 was taken by another process.
You can also find it by typing the following command in the powershell.
Get-Process -Id (Get-NetTCPConnection -LocalPort 443).OwningProcess
getaddrinfo failed means the hostname can't be resolved. Make sure the hostname you used is correct. Also check that there isn't another process listening on port 443.
To check which program is listening on port 443
netstat -ano -p tcp |find "443"
The command will return output similar to this
TCP 0.0.0.0:443 0.0.0.0:0 LISTENING 15096
To understand which is the program with that pid use the command(obviously use the pid that returned the previous command to you):
tasklist |find "15096"
Related
I am using the following code with python3.8.2 connecting to Cisco network devices (switch, router), running in an eveNG lab environment. I am connecting from a mac laptop, to a router using telnet on IP 10.9.249.3 and port 32769.
Problem is that when I run this code I do not get any output. I can however see the commands being run and the running config output on the device itself using a separate connection. The code execution just stays put waiting for an event.
from telnetlib import Telnet
HOST = "10.9.249.3"
tn = Telnet(HOST,32769)
tn.write(b"terminal length 0\n")
tn.write(b"show runn\n")
tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))
tn.exit()
When I do a control-break I get the following output:
^CTraceback (most recent call last):
File "p1.py", line 12, in <module>
print(tn.read_all().decode('ascii'))
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/telnetlib.py", line 335, in read_all
self.fill_rawq()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/telnetlib.py", line 526, in fill_rawq
buf = self.sock.recv(50)
KeyboardInterrupt
I found similar issues posted and tried their suggestions like changing to a different Telnet read_*() method but no change in the output.
One thing I have noticed is that when I connect to the network device, I have to do the following to disconnect the (manual) telnet connection:
ctrl-]
telnet> quit
Connection closed.
Thanks and regards,
Abid Ghufran
I use mcpi: https://github.com/AdventuresInMinecraft/AdventuresInMinecraft-Linux
Starting the local server.
After, run program:
import mcpi.minecraft as minecraft
mc = minecraft.Minecraft.create()
mc.postToChat("Hello Minecraft World")
I am facing the below error:
Traceback (most recent call last):
File "/home/home/AdventuresInMinecraft/MyAdventures/HelloMinecraftWorld.py", line 2, in mc = minecraft.Minecraft.create()
File "/home/home/.local/lib/python3.6/site-packages/mcpi/minecraft.py", line 376, in create return Minecraft(Connection(address, port))
File "/home/home/.local/lib/python3.6/site-packages/mcpi/connection.py", line 17, in init self.socket.connect((address, port))
ConnectionRefusedError: [Errno 111] Connection refused
A ConnectionRefusedError means that the address + port combination was unable to be secured for this particular Minecraft server and thus raised an exception. This could be because some other application is already using the port of interest, the port is unavailable because of the OS, or a handful of other networking configuration mishaps.
But perhaps a better series of questions to ask yourself is:
What is the default address and port that minecraft.Minecraft.create() will attempt to launch / listen at?
Do I have access to that server (address + port)?
If I do have access, are there any security issues (AKA Firewall)?
This post has already addressed the root issue of your question, and I hope it gives you a good start at understanding the foundation of your problem.
Notice how their question mentions s.connect((host,port)) and your stack trace has self.socket.connect((address, port)) Looks like the same thing to me!
Some more reading:
- localhost
- check if port is in use
I encountered the same issue. I looked into the code of mcpi and found that the default port is 4711. However, a Minecraft Server's default port is 25565. All you need to do is add 2 parameters on the create() function. Code(Python):
mc = minecraft.Minecraft.create(address="127.0.0.1", port=25565)
btw change "address" in the code to the host of the server (only if you modified the "server.properties" file).
Also, ConnectionRefusedError doesn't mean that it's not secured, I believe it means that either the server is not online, it doesn't exist, or the server refused it for some reason.
EDIT:
Oops sorry I just found out that mcpi actually connects to the RaspberryJam plugin which is hosted on another IP and port. The plugin runs on port 4711. So mcpi has the right port.
So check if you have the RaspberryJam plugin installed. If not, download it from
https://www.spigotmc.org/resources/raspberryjuice.22724/
And put the .jar file inside the plugins folder in your server directory.
I am trying to fix unfinished module for use in project, unfortunately, while trying to launching entry function of module ( main() ), i got an error.
At first, i got multiple errors, because if you look at original version of module, it's like this:
#click.option("--rmqhost", default="localhost", help="Rabbitmq host details")
#click.option("--redishost", default="localhost", help="Redis host details")
which uses IPv6 but my system is using IPv4.
But after i solved the first problem, now i got another one with IPv4:
Full log:
>>> from Exchange.exchange import main
>>> main()
INFO:Exchange.exchange:Exchange Service is starting
INFO:pika.adapters.base_connection:Connecting to 127.0.0.1:5672
WARNING:pika.adapters.base_connection:Connection to 127.0.0.1:5672 failed: [Errno 61] Connection refused
WARNING:pika.connection:Could not connect, 0 attempts left
ERROR:Exchange.exchange:Couldn't connect to rabbitmq, exiting!
What may the problem be? Is port 5672 occupied? Because when i tried lsof l :5672 in bash, it returned 0 (nothing). If not, then whats the problem and how could i fix it?
Thanks for your expertise, everyone. We're running a python server using Cherrypy to expose/handle our API. This use to run fine before upgrading Ubuntu 10.10 to 11.04 (with inherent python updates), but, unfortunately, since then CherryPy does not bind to port 80 (using a proxy port 9998). The error dump is as follows:
2015-03-24 23:21:16,610 cherrypy.error - INFO - [24/Mar/2015:23:21:16] ENGINE PID 17194 written to '/var/tmp/MYSERVERNAME.pid'.
2015-03-24 23:21:16,611 cherrypy.error - INFO - [24/Mar/2015:23:21:16] ENGINE Started monitor thread '_TimeoutMonitor'.
2015-03-24 23:21:16,611 cherrypy.error - INFO - [24/Mar/2015:23:21:16] ENGINE Started monitor thread 'Autoreloader'.
2015-03-24 23:21:21,771 cherrypy.error - ERROR - [24/Mar/2015:23:21:21] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0x12ffa90>>
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/cherrypy/process/wspbus.py", line 147, in publish
output.append(listener(*args, **kwargs))
File "/usr/lib/pymodules/python2.7/cherrypy/_cpserver.py", line 90, in start
ServerAdapter.start(self)
File "/usr/lib/pymodules/python2.7/cherrypy/process/servers.py", line 60, in start
self.wait()
File "/usr/lib/pymodules/python2.7/cherrypy/process/servers.py", line 101, in wait
wait_for_occupied_port(host, port)
File "/usr/lib/pymodules/python2.7/cherrypy/process/servers.py", line 266, in wait_for_occupied_port
raise IOError("Port %r not bound on %r" % (port, host))
IOError: Port 9998 not bound on '127.0.0.1'
Running netstat to see what is occupying the port shows:
alpha$ sudo netstat -pnl | grep 8080
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 17194/python
As you can see, the python server with PID 17194 starts up, starts cherrypy (which fails). I'm not sure what's colliding with what here. As you can probably tell, I'm not a server guy but that doesn't stop me from mucking around and messing things up! Anyone have a clue why CherryPy might not be binding?
I uninstalled CherryPy and reinstalled CherryPy to the latest (3.2), and the problem resolved itself.
I'm getting re-started with App Engine after not having used it in a while. I'm using the 64-bit Linux Go runtime, version 1.8.1.
I believe I'm following the steps from the documentation correctly, and I believe I'm doing what's worked correctly in the past, but I'm getting this error when attempting to launch dev_appserver.py:
$ dev_appserver.py .
INFO 2013-07-11 07:24:45,919 sdk_update_checker.py:244] Checking for updates to the SDK.
INFO 2013-07-11 07:24:46,230 sdk_update_checker.py:288] This SDK release is newer than the advertised release.
WARNING 2013-07-11 07:24:46,443 simple_search_stub.py:955] Could not read search indexes from /tmp/appengine.batterybotinfo.darshan/search_indexes
Traceback (most recent call last):
File "/home/darshan/bin/dev_appserver.py", line 182, in
_run_file(__file__, globals())
File "/home/darshan/bin/dev_appserver.py", line 178, in _run_file
execfile(script_path, globals_)
File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 695, in
main()
File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 688, in main
dev_server.start(options)
File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 659, in start
apis.start()
File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 137, in start
super(APIServer, self).start()
File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 295, in start
if self._start_all_dynamic_port(host_ports):
File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 348, in _start_all_dynamic_port
server.start()
File "/home/darshan/software/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 194, in start
socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
TypeError: getaddrinfo() argument 1 must be string or None
My first thought was that I might be using an incorrect version of Python. Sure enough, I'm using 2.7.5, and the documentation clearly states that 2.5 is necessary. However, the documentation seems to be outdated, because after installing 2.5 and setting my system to use it, I got this error:
Error: Python 2.5 is not supported. Please use version 2.7.
Okay, so back to 2.7.5 and my initial error.
I'm not sure if this is a bug in the dev_appserver.py Python code (I'm guessing not, as it's been out for a month), an issue with my Python installation, or something else about my system that isn't configured according to Google's expectations.
I'd rather not mess with the dev_appserver.py code unless necessary, but I'm happy to poke at it to help figure out what's going wrong. The error is on line 194; here are lines 190-195:
# AF_INET or AF_INET6 socket
# Get the correct address family for our host (allows IPv6 addresses)
host, port = self.bind_addr
try:
info = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
I've determined that the containing method is called twice. The first time host is always "127.0.0.1" and port is 0. The second time is the one that crashes; host is always 10 (an int, not a string), and port is a seemingly-random five-digit int.
I've tried hard-coding host to "127.0.0.1" and port to either 8080 or 0, but then I get another error. I feel in over my head, and I suspect I'm not going to resolve the real issue by changing things I don't really understand. Googling for the error message hasn't helped.
Persistent Googling eventually paid off. Despite this question having a very different (and much more informative) error message, the solution turned out to be the same: ensure that /etc/hosts contains only a single entry for localhost.
Notably, my system contained both of these lines:
127.0.0.1 localhost
::1 localhost
Commenting out the second (and adding a comment to document why) solved my issue:
127.0.0.1 localhost
# Having multiple localhost entries causes App Enginge dev_appserver.py to fail.
# IPv6 not currently needed, and the dev server IS needed, so commenting out.
#::1 localhost
dev_appserver.py now starts and works properly.
If you edit lines 189-194 to this, it should work until Google releases an update. This is basically just checking the type of host and returning early if it isn't a string.
189 # AF_INET or AF_INET6 socket
190 # Get the correct address family for our host (allows IPv6 addresses)
191 host, port = self.bind_addr
192 try:
193 if type(host) is not str:
194 return
195 info = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
196 socket.SOCK_STREAM, 0, socket.AI_PASSIVE)