Aborted connection error in flask - python

If the client closes an established connection that it has made with the flask server, I get the following error in the terminal:
[Errno 10053] An established connection was aborted by the software in your host machine
It seems when flask tries to write in the closed stream, it faces errors and hence will complain.
It seemed like a warning or so as the application does not quit after printing the error, but the problem is that my server will stop serving other requests despite being alive in the system.
I have read similar questions but they did not help. How can I prevent this issue? I use both Windows and Linux operating systems.

The cause of this problem is, as we previously discussed, insufficient permissions to perform the network operation. The remedy to the problem was to run the process as an administrator and/or to modify the system policy to allow connections on the restricted port.

Related

Random WinError 10060 when trying to connect to websocket

Background - using a windows machine, Windows 10/11, connected to the internet through ethernet cable. Using python's websocket-client module, on pycharm.
Problem - one fine day, out of the blue, I am no longer able to connect to FTX's websocket wss://ftx.com/ws/ on my local windows machine and kept getting the error [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
I tried on my VPS, a linux machine, with the same exact code and it works fine.
Attempts to fix the problem were:
A full reformat of computer, windows 10 > windows 10, and reinstall python 3.10 and pycharm.
Then upgrading windows 10 > windows 11.
Made sure all drivers are up to date, and also reinstalling them.
Resetting network settings from Windows
Tested the websocket connection with other end point and it worked fine. eg wss://api.gemini.com/v1/marketdata/BTCUSD
None of the above worked.
My websocket connection is in a while loop something like this
while True:
try:
ws.run_forever()
time.sleep(0.2)
except:
pass
So it would keep retrying.
There was a weird behavior when, from windows, I disable, and re-enable the network adapter, the websocket connection would suddenly be successful. And if I were to disable and re-enable the network adapter again; sometimes it would continue to fail, or sometimes the connection would be successful again. Note this is while the code is still executing in the while loop.
And, if I were to stop and re-run the code, it would never work, and the error WinError 10060 would arise.
At this point I am stumped and have no clue how to solve this problem as it was totally random and out of the blue. Looking for help and advise please..!

Suddenly: WinError 10054 Python Socket.py dependency

I know questions about WinError 10054 have been asked before, but solutions were not applicable in my case.
I have a dozen of scripts running on a daily basis, but as of yesterday a few of them crashed on the following error:
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
The scripts are both running on a local computer and a server (acceptance/production) and the strange thing is that on both machines the scripts now crash. In one case the script crashes on ftplib at the moment I try to retrieve a file from the ftp server by ftp.retrbinary(). Another script crashes when I try to close a webdriver, used for controlling the Chrome browser. Both are dependent on the socket.py library and the error traces back to: return self._sock.recv_into(b). Has there been some update recently that could cause this error?

flask server on raspberry pi stopped responding

I set up a flask server on my raspberry pi and set up a crontab to start the server on reboot. It was working fine for a while, for the past couple of days it stopped responding even after I rebooted the pi.
It seems like that the server is running because when I ssh in and try to run another server it says that the address is already in use.
Any ideas why my server is not responding anymore?
also, this may or may not be related but when I typed crontab -e I got the following error:
/tmp/crontab.Qqy98c: No space left on device
Creation of temporary crontab file failed - aborting
Address is already in use error indicates that some process is occupying the host/port that your Flask application is trying to use.
To resolve this problem, find out which processes are running on that port, then kill them. For example, if you use the default setting of port 5000, you can do the following in the terminal:
lsof -i:5000
This will show you the process that's running on port 5000 -- Take note of the process id. Let's say it's 12345 for example.
kill 12345
This should free up the address, allowing the Flask application to launch normally.
The error No space left on device Creation of temporary crontab file failed should be somewhat self-explanatory. If you're running so low on file space, you should strongly consider clearing up space. Otherwise, you're bound to run into all kinds of problems.

PyCharm remote debugging (pydevd) does not connect

PyCharm remote debugging (pydevd) does not connect with the following message:
error: [Errno 10061] No connection could be made because the target machine actively refused it
How can I troubleshoot it?
The output console in PyCharm shows:
Starting debug server at port 21000
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('*.*.*.*', port=21000, suspend=False)
Waiting for process connection...
Server stopped.
I checked the firewall and PyCharm is allowed for both incoming and outgoing connections.
10061 is WSAECONNREFUSED, 'connection refused', which means there was nothing listening at the IP:port you tried to connect to.
Though I see that you have validated its not a firewall issue, but still I would suggest to check the port numbers again with respect to the ones opened in windows firewall. Or to narrow down just run a simplehttpserver or icmp server at the same port and confirm.
In a direct link communication, it often means that you have already something connected to this port.
To check what process is hearing what port, check this SO question.
You can then either kill the program or change the port, depending of what you can do.
Without more information of the "remote tested", it is hard to know what is happening.
I was having the trouble as well (Server stopped as soon as the client connected).
Turned out that I had apparently too many breakpoints defined.
after having removed most of them and re-initiated my remote debug connection from the client (and having restarted the debug server in pycharm) it doesn't trigger anymore the "Server stopped." problem.

Python Fabric: Skip refused SSH connections?

I'm new to Python and Fabric, and I've modified a script that pings hosts on our LAN (to determine what machines are alive, we have a lot) to log into the hosts and list running processes back to the client. Whilst this works on servers, it seems there's other devices in the subnets that don't permit SSH logins and the connection is refused, causing Fabric to exit with a fatal error. Is there any way to make Fabric skip any host that refuses a connection?
Using
with settings(warn_only=True)
doesn't seem to help.
Thanks.
You can set this env var or also use this flag. Searching the docs, if you can't find it in a heading, is best.

Categories

Resources