This is a simple HTTPS python server (not for production use)
# libraries needed:
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl , socket
# address set
server_ip = '0.0.0.0'
server_port = 3389
# configuring HTTP -> HTTPS
httpd = HTTPServer((server_ip, server_port), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile='./public_cert.pem',keyfile='./private_key.pem', server_side=True)
httpd.serve_forever()
as you see in the above script i wrap a simple python HTTP server with ssl certificate and make it a simple HTTPS server
Detailed example of python simple HTTPS server
Is there a way to ssl wrap any, already running HTTP server to HTTPS server ?
Suppose I have a HTTP server running at port 8080. Can I just ssl wrap it to port 443?
Related
I am using python http.server 80 to expose my downloaded files to my twilio whatsapp bot
is there a way that as my django-twillio app starts it automatically runs the server on port 80 as well
python -m http.server 80
Adding this code to your django-twilio app will programmatically start your server on localhost:80
from http.server import HTTPServer, SimpleHTTPRequestHandler
httpd = HTTPServer(('localhost', 80), SimpleHTTPRequestHandler)
httpd.serve_forever()
I have dockerized a simple OPC UA server. When I run it locally, I am capable of connecting to the server without problems. However, when I run the server in a Docker container the client refuses to connect. Further, when I try to set the endpoint for the server as opc.tcp://localhost:4840, the server will not bind to the address when it is ran inside a container. The endpoint opc.tcp://127.0.0.1:4840 must be used. This is not an issue when running the server locally. The following library is used to implement the server https://github.com/FreeOpcUa/python-opcua and the client used is https://github.com/FreeOpcUa/opcua-client-gui.
I have tried to set different endpoints without any luck.
The server implementation is:
from opcua import Server, ua
server = Server()
server.set_endpoint('opc.tcp://127.0.0.1:4840')
server.set_security_policy([ua.SecurityPolicyType.NoSecurity])
server.start()
try:
while True:
i = 1
finally:
server.stop()
The 'Dockerfile' exposes the following port EXPOSE 4840. The Docker run command is
docker run --rm --name server -p 4840:4840 opcua
You server in container is only listening to 127.0.0.1, hence only accepting connection from inside the container:
server.set_endpoint('opc.tcp://127.0.0.1:4840')
You should listen to all hosts such as:
server.set_endpoint('opc.tcp://0.0.0.0:4840')
you need to use --network host in your docker run command , since localhost on the conatiner is not your host
My Couchbase server is configured with a non-default port (for example):
web admin port : 31100
direct port : 31200
api port : 31221
memcached port : 31222
My connection string is couchbase://localhost:31100/my_bucket but it's not working.
How can I connect a Couchbase server in Python?
I am using python FTP server and client program. My need is to run Python FTP server on a remote machine that is connected on the same network as my local machine. FTP client will run from local machine, I need to connect FTP server with my FTP client running on local machine.
Please help!
This is my ftpserver.py:
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
authorizer = DummyAuthorizer()
authorizer.add_user("lokesh", "123", "current_dir", perm="elradfmw")
authorizer.add_anonymous("curent_dir", perm="elradfmw")
handler = FTPHandler
handler.authorizer = authorizer
server=FTPServer(("localhost",8080),handler)
server.serve_forever()
This is my ftpclient.py that needs to connect with the above server:
from ftplib import FTP
ftp = FTP('')
host='localhost'
port=8080
ftp.connect(host,port)
ftp.login()
print(ftp.getwelcome())
print('Current Directory ',ftp.pwd())
ftp.dir()
ftp.quit()
When I test my server and client on same machine it worked. But when I run the same server on another machine and tried to connect with my client it gave me error:
error: [Errno 10061] No connection could be made because the target
machine actively refused it
If you run the client on another machine, you have to connect to the host of the server, not to "localhost":
host='<server_host>'
Run ipconfig on your Windows server machine and look for "IPv4 address".
Replace port = 1027 with port = 8080 in your ftpclient file.
how can i implement a server that receives and parse mails, like using the library
from smtpd import SMTPServer
but running forever under wsgi like http://webpython.codepoint.net/wsgi_environment_dictionary