Because the new version of openssl removes support for 3DES, I have to use this lib to send raw socket request which not use libopenssl.
I read the docs and test demo from python-gnutls's website page that hosted on github.
Here is my code:
win10 python 3.9 python-gnutls 3.1.3 gnutls 3.5.19
import socket
from gnutls.connection import *
# this is the host only 3DES under TLS1.0, even though there is a # 302 redirection.
# hostname = 'www.mycardtamoil.it'
hostname = 'stackoverflow.com'
ctx = TLSContext(X509Credentials())
sock = socket.create_connection((hostname, 443))
s = ClientSession(sock, ctx)
s.handshake()
print(s.peer_certificate.subject)
print(s.protocol.decode(), s.cipher.decode())
#s.send(f'GET / HTTP/1.1\r\nHost: {hostname}\r\n\r\n') Wrong usage
s.send(memoryview(f'GET / HTTP/1.1\r\nHost: {hostname}\r\n\r\n\r\n'.encode()))
print(s.recv(1024).decode())
s.bye()
s.close()
The result with Wrong usage which not use memoryview type :
CN=*.stackexchange.com
TLS1.2 AES-128-GCM
HTTP/1.1 400 Bad Request
Connection: close
Content-Length: 11
content-type: text/plain; charset=utf-8
Now the problem is how to send a GET request to normal website.
I have solved this problem at 2021-04-29.
s.send(memoryview(f'GET / HTTP/1.1\r\nHost: {hostname}\r\n\r\n\r\n'.encode()))
Write
s.send(f'GET / HTTP/1.1\r\nHost: {hostname}\r\n\r\n')
Wrong type used