无法完成到0000:0000:0000:0000:0000:0000:0000:0000:0000:0

时间:2019-04-27 08:29:45

标签: python-3.x socks pycurl

我正在尝试使用以下方法在Docker容器中通过socks5代理下载文件:

    def requests_get(url):
        buffer = io.BytesIO()
        try:
            c = pycurl.Curl()
            c.setopt(c.URL, url)
            c.setopt(pycurl.USERAGENT, random.choice(uas))
            c.setopt(pycurl.FOLLOWLOCATION, True)
            c.setopt(pycurl.HEADER, True)
            c.setopt(pycurl.VERBOSE, False)
            c.setopt(pycurl.PROXY, random.choice(proxy_IPS))
            c.setopt(pycurl.PROXYUSERPWD, "{}:{}".format(proxy_usr, proxy_psw) )
            c.setopt(pycurl.PROXYPORT, 1080)
            c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
            c.setopt(pycurl.SSL_VERIFYPEER, False)
            c.setopt(pycurl.SSL_VERIFYHOST, False)
            c.setopt(pycurl.COOKIEFILE, "")
            c.setopt(c.WRITEDATA, buffer)
            c.perform()
            c.close()
            return dict(
                text = buffer.read(),
                status_code = c.getinfo(pycurl.HTTP_CODE)
            )
        except Exception as ex:
            print (ex)
            return dict(text='', status_code=599)

虽然在php中没有问题,但在python中会返回以下异常。

Can't complete SOCKS5 connection to 0000:0000:0000:0000:0000:0000:0000:0000:0. (2)

我已经尝试过给它一个请求旋转,但是它也不起作用。

0 个答案:

没有答案