'Why does requests crash my python script after a restart?
I'm trying to connect two python clients, a terminal and a client, over a express.js server but when I restart my client it keeps crashing and requets gives me an error. The terminal is fine though... Here is my terminal code:
import requests
command = ""
commandJSON = {}
while True:
command = input("rcv@user>>>")
commandJSON = {"data": command}
status = requests.post("http://MY_IP:3000/upload", json=commandJSON)
print(requests.get("http://MY_IP:3000/downloadOutput"))
print("Upload-status: " + str(status))```
...and my client...
import requests
import subprocess
import os
print("Running...")
output = ""
command = "<Response [200]>"
while True:
command = str(requests.get("http://192.168.0.182:3000/download"))
if command != "<Response [200]>":
if command == "hi":
output = "received"
sendJSON = {"data": output}
requests.post("http://192.168.0.182:3000/uploadOutput", json=sendJSON)
print(command)
Here is the errormsg:
Traceback (most recent call last): File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\connection.py", line 174, in _new_conn conn = connection.create_connection( File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection raise err File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection sock.connect(sa) OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen httplib_response = self._make_request( File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\connectionpool.py", line 398, in _make_request conn.request(method, url, **httplib_request_kw) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\connection.py", line 239, in request super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\http\client.py", line 1285, in request self._send_request(method, url, body, headers, encode_chunked) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\http\client.py", line 1331, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\http\client.py", line 1280, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\http\client.py", line 1040, in _send_output self.send(msg) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\http\client.py", line 980, in send self.connect() File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\connection.py", line 205, in connect conn = self._new_conn() File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\connection.py", line 186, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000024EABA4D910>: Failed to establish a new connection: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\requests\adapters.py", line 440, in send resp = conn.urlopen( File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen retries = retries.increment( File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\urllib3\util\retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.0.182', port=3000): Max retries exceeded with url: /download (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000024EABA4D910>: Failed to establish a new connection: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Marcz\Desktop\Niklas\Python\Projects\rcv_client\client.py", line 11, in command = str(requests.get("http://192.168.0.182:3000/download")) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\requests\api.py", line 75, in get return request('get', url, params=params, **kwargs) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\requests\api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\requests\sessions.py", line 529, in request resp = self.send(prep, **send_kwargs) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\requests\sessions.py", line 645, in send r = adapter.send(request, **kwargs) File "C:\Users\Marcz\Desktop\Niklas\Python\Versions\3.9.8\lib\site-packages\requests\adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.0.182', port=3000): Max retries exceeded with url: /download (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000024EABA4D910>: Failed to establish a new connection: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted'))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
