问题描述
因为新版本的 openssl 取消了对 3DES 的支持,所以我必须使用这个 lib 来发送不使用 libopenssl 的原始套接字请求。
我从托管在 github 上的 python-gnutls 网站页面阅读了文档和测试演示。
这是我的代码:
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()
不使用内存视图类型的错误使用结果:
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
现在的问题是如何向普通网站发送GET请求。
我在2021-04-29解决了这个问题。s.send(memoryview(f'GET / HTTP/1.1\r\nHost: {hostname}\r\n\r\n\r\n'.encode()))
写s.send(f'GET / HTTP/1.1\r\nHost: {hostname}\r\n\r\n')
使用了错误的类型
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)