I have two files, client.py and server.py:
client.py
from urllib import request
response = request.urlopen('http://localhost:8000/info')
print('The server said:', response.read())
server.py
from http.server import HTTPServer, BaseHTTPRequestHandler
class CustomServer(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/info':
result = 'Hello this is a server'
else:
result = 'Invalid'
self.send_response(200)
self.end_headers()
self.wfile.write(result.encode())
server = HTTPServer(('localhost', 8000), CustomServer)
server.serve_forever()
Both these files work well independently:
- If I alter client.py to request
http://stackoverflow.com
, I see the proper html result. - If I run server.py and use my browser to navigate to
localhost:8000/info
, I seeHello this is a server
My problem is when I run the server, then the client, as-is. The client will receive an error: Connection Refused
, with errno 61
.
This error only occurs on a particular MacOS machine. When the same code is run on other machines everything works correctly.
What could be causing this problem?