FlorianREGAZ / Python-Tls-Client

Advanced HTTP Library
MIT License
678 stars 135 forks source link

The response.content returned data is incorrect #64

Open wangluozhe opened 1 year ago

wangluozhe commented 1 year ago

If additional_ Decode=None, and add Accept Encoding="gzip, deflate, br" in the headers. The data returned after the request will not be correctly decoded by gzip, which only raises a problem. If the encoding format is not gzip, deflate, br, but other compressed data, then I will not decode successfully. Provide sample code:

import tls_client
import gzip

tls_config = {
    "ja3_string": "771,4865-4867-4866-49195-49199-52393-52392-49196-49200-49162-49161-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-34-51-43-13-45-28-21,29-23-24-25-256-257,0",
    "supported_signature_algorithms": [
        "ECDSAWithP256AndSHA256",
        "ECDSAWithP384AndSHA384",
        "ECDSAWithP521AndSHA512",
        "PSSWithSHA256",
        "PSSWithSHA384",
        "PSSWithSHA512",
        "PKCS1WithSHA256",
        "PKCS1WithSHA384",
        "PKCS1WithSHA512",
        "ECDSAWithSHA1",
        "PKCS1WithSHA1"
    ],
    "supported_versions": [
        "1.3",
        "1.2"
    ],
    "additional_decode": None,
}
session = tls_client.Session(**tls_config)
url = "https://yopmail.com/zh/"
headers = {
    "Accept": "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",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    "Pragma": "no-cache",
    "sec-ch-ua": "\".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "Sec-Fetch-Dest": "document",
    "Sec-Fetch-Mode": "navigate",
    "Sec-Fetch-Site": "none",
    "Sec-Fetch-User": "?1",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
}
response = session.get(url, headers=headers, proxy="http://127.0.0.1:7890")
print(response.content)
print(gzip.decompress(response.content))
print(response.text)
print(response.headers)

Error message: gzip.BadGzipFile: Not a gzipped file (b'\x1f\xef')

ItsCEED commented 1 year ago

BUmp, anyone got this fixed?

2024baibai commented 1 year ago

Any one know that how to resolve?

2024baibai commented 1 year ago

Any one know that how to resolve?

Use the parameter additional_decode="gzip", But I prefer It can auto decode