lexiforest / curl_cffi

Python binding for curl-impersonate fork via cffi. A http client that can impersonate browser tls/ja3/http2 fingerprints.
https://curl-cffi.readthedocs.io/
MIT License
2.49k stars 265 forks source link

[Feature] Websocket work #392

Open Cataphract89 opened 2 months ago

Cataphract89 commented 2 months ago

I need to set up a large number of websocket connections to the site\app. At my volume I am starting to get connection errors. I manage to get around this by randomizing impersonate:

     impersonate=random.choice(['chrome110, chrome120, ...])

And using custom settings for the latest version of chrome128 with several variants ja3 static customizations of real android devices

    tls_version = "771"
cipher_suites = "4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53"
supported_groups = "25497-29-23-24"
compression_methods = "0"
possible_extensions = [
    "0", "5", "10", "11", "13", "16", "18", "23", "27", "35", "43", "45", "51",
    "65281", "65037", "17513"
]
akamai = "1:65536;2:0;4:6291456;6:262144|15663105|0|m,a,s,p"

extra_fp = {
    "tls_signature_algorithms": [
        "ecdsa_secp256r1_sha256",
        "rsa_pss_rsae_sha256",
        "rsa_pkcs1_sha256",
        "ecdsa_secp384r1_sha384",
        "rsa_pss_rsae_sha384",
        "rsa_pkcs1_sha384",
        "rsa_pss_rsae_sha512",
        "rsa_pkcs1_sha512",
    ],
    'tls_cert_compression': "brotli",
    'http2_stream_weight': 256,
    'http2_stream_exclusive': 1
}
extensions = gen_random_extensions(possible_extensions)
ja3 = ",".join(
    [
        tls_version,
        cipher_suites,
        extensions,
        supported_groups,
        compression_methods,
    ]
)

(IOS works the worst, and the latest custom version gives only errors) But after a while, I'm starting to run into more and more connection errors.. Websocket settings

                   if not self.imp:
                ws = s.ws_connect(
                    url,
                    on_message=self.on_message, proxies={
                        'https': f"http://{self.proxies_ws['login']}:"
                                 f"{self.proxies_ws['password']}@{self.proxies_ws['ip']}:{rand_port}"},
                    headers=headers, on_error=self.on_error, ja3=self.ja3, extra_fp=self.extra_fp, akamai=self.akamai)
            else:
                ws = s.ws_connect(
                    url,
                    on_message=self.on_message, proxies={
                        'https': f"http://{self.proxies_ws['login']}:"
                                 f"{self.proxies_ws['password']}@{self.proxies_ws['ip']}:{rand_port}"},
                    headers=headers, on_error=self.on_error, impersonate=self.imp)

Question - am I missing something in the websocket operation and is the setup different from the requests? How can I randomize more settings for successful connections ?

Cataphract89 commented 2 months ago

My other similar question pertaining to the same thing - Android extensions randomize https://github.com/lexiforest/curl_cffi/issues/393