Python's requests “Missing dependencies for SOCKS support” when using SOCKS5 from Terminal

后端 未结 14 890
南笙
南笙 2020-12-12 20:36

I\'m trying to interact with an API from my Python 2.7 shell using a package that relies on Python\'s requests. Thing is the remote address is blocked by my network (univers

相关标签:
14条回答
  • 2020-12-12 21:04

    Just unset your all_proxy environment variable, and this should work. Also you can refer to this issue in github.

    On Ubuntu you can use the following command unset all_proxy and restart terminal

    0 讨论(0)
  • 2020-12-12 21:07

    You must add socks support with python requests library:

    pip install requests[socks]
    
    0 讨论(0)
  • 2020-12-12 21:08

    In debian 10, Python 3:

    pip3 install pysocks
    
    0 讨论(0)
  • 2020-12-12 21:13

    I faced the same issue where got the error Missing dependencies for SOCKS support. with Anaconda Python 3.7

    As conda command was working fine, I installed pysocks with the command conda install pysocks

    This resolved the issue.

    0 讨论(0)
  • 2020-12-12 21:14

    I also stumbled upon this issue while doing a simple pip install -U pip, but information I found from your question helped me resolved my issue. I am on Mac OS X.

    As you have pointed out, adapters.py from the requests package was trying to do this:

    try:
        from .packages.urllib3.contrib.socks import SOCKSProxyManager
    except ImportError:
        def SOCKSProxyManager(*args, **kwargs):
            raise InvalidSchema("Missing dependencies for SOCKS support.")
    

    So it seems sensible to look for the place of definition of SOCKSProxyManager. It seems to be in a "contrib" module in urllib3 and not installed alongside urllib3 by default. The docstring of that module says:

    This module contains provisional support for SOCKS proxies from within
    urllib3. This module supports SOCKS4 (specifically the SOCKS4A variant) and
    SOCKS5. To enable its functionality, either install PySocks or install this
    module with the ``socks`` extra.
    

    The instructions of the pip docs says this about setuptools extras:

    6. Install a package with setuptools extras.
    
    $ pip install SomePackage[PDF]
    $ pip install git+https://git.repo/some_pkg.git#egg=SomePackage[PDF]
    $ pip install SomePackage[PDF]==3.0
    $ pip install -e .[PDF]==3.0  # editable project in current directory
    

    So I followed the instructions and did:

    $ pip install 'urllib3[socks]'
    

    I then continued with pip install -U pip, which was what I was supposed to be doing, and now it works.

    I wonder how many people got tricked-up by the square brackets, as Bash and other shells often treat it as a special character, which needs to be escaped for it to reach the invoked program (in this case, pip).

    0 讨论(0)
  • 2020-12-12 21:14

    In ubuntu, I do the following commands:

    # Unset socks proxy
    unset all_proxy    
    unset ALL_PROXY
    # Install missing dependencies:
    pip install pysocks
    # Reset proxy
    source ~/.bashrc
    
    0 讨论(0)
提交回复
热议问题