Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Cannot change proxy on the fly #369

Open
sd5986 opened this issue Aug 13, 2024 · 5 comments
Open

[BUG] Cannot change proxy on the fly #369

sd5986 opened this issue Aug 13, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@sd5986
Copy link

sd5986 commented Aug 13, 2024

Describe the bug

After you make a request to a website (i.e first request) with a proxy server, in the second request, try to use another proxy server, it would not work.

    raise RequestsError(str(e), e.code, rsp) from e
curl_cffi.requests.errors.RequestsError: Failed to perform, curl: (35) BoringSSL SSL_connect: SSL_ERROR_SYSCALL in connection to www.google.com:443 . See https://curl.se/libcurl/c/libcurl-errors.html first for more details.

I have tried using a.s.proxies = {'https': 'socks5h://127.0.0.1:2085/'} as well. After changing, it also gives the same error.

To Reproduce

from curl_cffi import requests

class new_ins():

    def __init__(self):
        self.s = requests.Session(impersonate='chrome124')
        self.original_get = self.s.get
        self.s.get = self.override_cffi_get
    def override_cffi_get(self,*args,**kwargs):
        print(args)
        print(kwargs)
        response = self.original_get(*args,**kwargs)
        return response


def req():

    #s = httpx.Client()
    a = new_ins()
    # a.s.proxies = {'https': 'socks5h://127.0.0.1:2080/',
    #                'http': 'socks5h://127.0.0.1:2080/'}
    proxy = 'socks5h://127.0.0.1:2080/'
    print(a.s.get(url='https://www.google.com/',proxy=proxy).content)
    #a.s.proxies = {'https': 'socks5h://127.0.0.1:2085/'}
    #a.s.curl.setopt(curl_cffi.CurlOpt.PROXY,'socks5h://127.0.0.1:2085')
    input()
    proxy = 'socks5://127.0.0.1:2085/'
    print(a.s.get(url='https://www.google.com/',proxy=proxy).content)
    input()

Expected behavior
A clear and concise description of what you expected to happen.

The program will be change it's proxy server in the next request

Versions

  • OS: Mac OS 14.5, Ubuntu
  • curl_cffi version [e.g. 0.5.7]
  • pip freeze dump

Additional context

  • Which session are you using? async or sync?
  • If using async session, which loop implementation are you using?
@sd5986 sd5986 added the bug Something isn't working label Aug 13, 2024
@perklet
Copy link
Collaborator

perklet commented Aug 14, 2024

- a.s.curl.setopt(curl_cffi.CurlOpt.PROXY,'socks5h://127.0.0.1:2085')
+ proxy = 'socks5://127.0.0.1:2085/'

It seems that you switched from socks5h to socks5 accidentally.

@sd5986
Copy link
Author

sd5986 commented Aug 14, 2024

- a.s.curl.setopt(curl_cffi.CurlOpt.PROXY,'socks5h://127.0.0.1:2085')
+ proxy = 'socks5://127.0.0.1:2085/'

It seems that you switched from socks5h to socks5 accidentally.

Nah I did it intentionally to see if socks5/socks5h caused the problem. I also tried socks5h as well. It won't work. Btw, this might be a libcurl bug

@perklet
Copy link
Collaborator

perklet commented Aug 14, 2024

I only found curl/curl#648, which has been fixed, though.

@sd5986
Copy link
Author

sd5986 commented Aug 19, 2024

I only found curl/curl#648, which has been fixed, though.

I do not know why this bug happens too :( . But create a new session and copy headers, cookies to the new one with another proxy server specified, works flawlessly.

@mafuyuuu1
Copy link

Try adding verify=False
self.s = requests.Session(impersonate='chrome124', verify=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants