From 2de3793bce16e9cd6a38af10a3cf3a7b0ede533c Mon Sep 17 00:00:00 2001 From: Valentine Date: Mon, 29 Jan 2024 00:07:40 +0300 Subject: [PATCH] fix socks proxy without auth --- scraper.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scraper.go b/scraper.go index 9852eee..98326c6 100644 --- a/scraper.go +++ b/scraper.go @@ -143,7 +143,16 @@ func (s *Scraper) SetProxy(proxyAddr string) error { host := proxyURL.Hostname() port := proxyURL.Port() - dialSocksProxy, err := proxy.SOCKS5("tcp", host+":"+port, &proxy.Auth{User: username, Password: password}, baseDialer) + var auth *proxy.Auth + + if username != "" || password != "" { + auth = &proxy.Auth{ + User: username, + Password: password, + } + } + + dialSocksProxy, err := proxy.SOCKS5("tcp", host+":"+port, auth, baseDialer) if err != nil { return errors.New("error creating socks5 proxy :" + err.Error()) }