Search on blog:

Python: How to send HTTPS request using PySocks

To connect with secure HTTPS you need module ssl to create wrapper on original socket.

import socks
import ssl

s = socks.socksocket()

#s.set_proxy(socks.SOCKS5, "localhost", 9050)  # TOR proxy server

s.connect(("", 443))
ss = ssl.wrap_socket(s, keyfile=None, certfile=None, server_side=False, cert_reqs=ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_SSLv23)

request = "GET /get HTTP/1.1\r\nHost:\r\nConnection: close\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\r\nSec-Fetch-Site: none\r\nSec-Fetch-Mode: navigate\r\nSec-Fetch-Dest: document\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7\r\n\r\n"

result = ss.recv(4096)
while result:
     result = ss.recv(1024)

Example uses page to see sended data.

I comment there is option to use network TOR using local proxy server.

Sometimes ssl may need to install newer version of OpenSSL


Stackoverflow: How to send https reuqest using pysocks python

In other post I shows how to use network TOR with module requests and how to use socket to change IP in network TOR.

If you like it
Buy a Coffee