SickGear/SickGear

Using socks proxy

ellnic opened this issue · 11 comments

Branch: master

Branch version commit hash: docker @ 0.21.5

Expectation Result
To be able to enter socks5://someip:someport or socks://someip:someport and (ideally) a username and password Testing with socks authentication disabled as there is nowhere to input credentials, but an error occurs.

I have tried prefixing with socks and socks5, no improvement.

Steps to reproduce:
1) Enter a socks address in the proxy field
2) Save

1) Detail... Unable to determine SOCKS version from socks://192.168.0.200:9118
 2) Traceback (most recent call last):
 3)   File "/opt/SickGear/lib/sg_helpers.py", line 299, in get_url
 4)     response = session.get(url, timeout=timeout, **kwargs)
 5)   File "/opt/SickGear/lib/requests/sessions.py", line 550, in get
 6)     return self.request('GET', url, **kwargs)
 7)   File "/opt/SickGear/lib/cfscrape/__init__.py", line 54, in request
 8)     resp = super(CloudflareScraper, self).request(method, url, *args, **kwargs)
 9)   File "/opt/SickGear/lib/requests/sessions.py", line 537, in request
10)     resp = self.send(prep, **send_kwargs)
11)   File "/opt/SickGear/lib/requests/sessions.py", line 650, in send
12)     r = adapter.send(request, **kwargs)
13)   File "/opt/SickGear/lib/cachecontrol/adapter.py", line 53, in send
14)     resp = super(CacheControlAdapter, self).send(request, **kw)
15)   File "/opt/SickGear/lib/requests/adapters.py", line 412, in send
16)     conn = self.get_connection(request.url, proxies)
17)   File "/opt/SickGear/lib/requests/adapters.py", line 309, in get_connection
18)     proxy_manager = self.proxy_manager_for(proxy)
19)   File "/opt/SickGear/lib/requests/adapters.py", line 182, in proxy_manager_for
20)     manager = self.proxy_manager[proxy] = SOCKSProxyManager(
21)   File "/opt/SickGear/lib/urllib3/contrib/socks.py", line 192, in __init__
22)     raise ValueError("Unable to determine SOCKS version from %s" % proxy_url)
23) ValueError: Unable to determine SOCKS version from socks://192.168.0.200:9118

Additional notes:
There are no specific config settings, start with a blank config and just enter a socks proxy.

This is what the standard Python code that throws that error says...

        parsed = parse_url(proxy_url)

        if username is None and password is None and parsed.auth is not None:
            split = parsed.auth.split(":")
            if len(split) == 2:
                username, password = split
        if parsed.scheme == "socks5":
            socks_version = socks.PROXY_TYPE_SOCKS5
            rdns = False
        elif parsed.scheme == "socks5h":
            socks_version = socks.PROXY_TYPE_SOCKS5
            rdns = True
        elif parsed.scheme == "socks4":
            socks_version = socks.PROXY_TYPE_SOCKS4
            rdns = False
        elif parsed.scheme == "socks4a":
            socks_version = socks.PROXY_TYPE_SOCKS4
            rdns = True
        else:
            raise ValueError("Unable to determine SOCKS version from %s" % proxy_url)

which makes sense from the log that you posted with NO socks version...
23) ValueError: Unable to determine SOCKS version from socks://192.168.0.200:9118

All I can think of other than bad Proxy host setting is to restart SG after saving - although your log does not seem to indicate you need to do that. So try with a valid scheme... e.g. socks5://192.168.0.200:9118, and then check your log.

I have already tried with socks5:// and just ip:port. The proxy may well be to blame, as it's normally run with authentication, but there is nowhere to enter a user/pass for the proxy in the SG interface. Any chance this could be added?

No need.

You can see from the code that those details are parsed from the industry standard proxy scheme that is passed, so just use the correct scheme that includes username/password and you will be fine.

There is not an actual issue here, therefore, as per our normal handling, this thread will now be marked invalid. Feel free to ask anything else below, even though it is closed that's no problem.

Good luck.

Ahh, ok do you mean this?

user:password@proxyserver:proxyport

like this... socks5://user:pass@host:port

Tried a few other things and varying combinations etc and it's still not working. Thanks for the help anyway.

We think we know the issue, however, for you to test is troublesome unless you know how to use the other docker. Therefore, the fix will be pushed out in the hope it fixes it for you - in the next release version.

If you know how to switch to the other test docker, then you will be able to switch to the hotfix branch and test the fix now.

Great, I can do that. I need to go out for a couple of hours, I will test and report back in a bit. Thanks!

Awesome stuff! hotfix/0.21.6 appears to have fixed it. I can confirm that I now see connections to various providers and results coming in instead of a ton of socks related errors. I would stay on the dev docker, but for some reason it doesn't want to just fire up with a copy of my old config. I will wait for the hotfix on master. Thank you very much for such prompt and helpful support! ❤️

Fixed here

Thanks for the report.

@JackDandy Thank you very much, all working well!