Python使用socks代理

参考:How to make python Requests work via socks proxy - Stack Overflow

使用pysocks库 - Jim's answer

As of requests version 2.10.0, released on 2016-04-29, requests supports SOCKS.

It requires PySocks, which can be installed with pip install pysocks.

Install:

pip install pysocks

or

pip install -U requests[socks]

Example usage:

import requests
proxies = {'http': "socks5://myproxy:9191"}
requests.get('http://example.org', proxies=proxies)

requests.exceptions.ConnectionError报错 - Mahmoud Hashemi's answer

In case someone has tried all of these older answers, and is still running into problems like:

requests.exceptions.ConnectionError:
SOCKSHTTPConnectionPool(host='myhost', port=80):
Max retries exceeded with url: /my/path
(Caused by NewConnectionError('<requests.packages.urllib3.contrib.socks.SOCKSConnection object at 0x106812bd0>:
Failed to establish a new connection:
[Errno 8] nodename nor servname provided, or not known',))

It may be because, by default, requests is configured to resolve DNS queries on the local side of the connection.

Try changing your proxy URL from socks5://proxyhost:1234 to socks5h://proxyhost:1234. Note the extra h (it stands for hostname resolution).

The PySocks package module default is to do remote resolution, and I'm not sure why requests made their integration this obscurely divergent, but here we are.

Python使用socks代理的更多相关文章

  1. python抓取数据,python使用socks代理抓取数据

    在python中,正常的抓取数据直接使用urllib2 这个模块: import urllib2 url = 'http://fanyi.baidu.com/' stream = urllib2.ur ...

  2. [转]使用 mitmproxy + python 做拦截代理

    使用 mitmproxy + python 做拦截代理   本文是一个较为完整的 mitmproxy 教程,侧重于介绍如何开发拦截脚本,帮助读者能够快速得到一个自定义的代理工具. 本文假设读者有基本的 ...

  3. 【转载】SOCKS代理:从***到内网漫游

    原文:SOCKS代理:从***到内网漫游 本文原创作者:tahf,本文属FreeBuf原创奖励计划,未经许可禁止转载 之前在Freebuf上学习过很多大牛写的关于Tunnel.SOCKS代理.***等 ...

  4. steam linux 使用socks代理

    环境:Ubuntu 15.10 64bit,Steam:built:May 10 2016 需要的工具:ssh/shadowsocks等socks5代理,tsocks ---------------- ...

  5. 内网隧道与SOCKS代理思路总结

    早就想总结一下这部分内容了,总是有其他事情卡住,一直拖到现在 内网中有很多边界设备,比如防火墙.这种边界设备会控制内部主机的对外连接,一般会仅允许某些种类的端口开放或某种数据流量出入 这就意味着我们只 ...

  6. redsocks 将socks代理转换成全局代理

    redsocks 需要手动下载编译.前置需求为libevent组件,当然gcc什么的肯定是必须的. 获取源码 git clone https://github.com/darkk/redsocks 安 ...

  7. Mac Aria2 使用Privoxy将socks代理转化为http代理

    安装Privoxy 打开终端安装privoxy来实现这里我是通过brew来进行的安装 brew install privoxy 看到这行已经安装成功 ==> Caveats To have la ...

  8. 使用ssh正向连接、反向连接、做socks代理的方法

     ssh -L 219.143.16.157:58080:172.21.163.32:8080 用户名@localhost -p 10142  在 219.143.16.157机器执行   将ssh隧 ...

  9. Winet API 支持HTTPP/SOCKS代理

    源程序 1.Winet API 支持使用IE代理.或者不使用代理.或者使用自定义代理三种方式. 2.使用自定义代理的话,支持HTTP代理,SOCKS代理,但是SOCKS代理不知支持用户名密码,HTTP ...

  10. 给HttpClient添加Socks代理

    本文描述http client使用socks代理过程中需要注意的几个方面:1,socks5支持用户密码授权:2,支持https:3,支持让代理服务器解析DNS: 使用代理创建Socket 从原理上来看 ...

随机推荐

  1. YieldReturn语法解析

    /* * * 学习Yield Return 语法 * 使用两个方法,显示1 - 100之间的全部偶数 * * */ using System;using System.Collections.Gene ...

  2. python logger 按时间段滚动

    import logging import logging, logging.handlers import time logging.getLogger().setLevel(logging.DEB ...

  3. tomcat8 无法解析 请求url 中 包含 [: 或者 :] 等特殊符号

    使用如下URL: http://127.0.0.1:8080/xx/[:xOGxeSSk5ENaYh89ziEFJA==:].do 如果使用tomcat8 无法正常访问,浏览器network 报错 4 ...

  4. vue仿QQ聊天室|vue聊天实例,直播聊天室

    图片压缩 百亿站点 基于vue2.0+vue-cli+vuex+vue-router+webpack+es6+wcPop等技术开发的仿微信聊天界面|仿微信聊天室vue-chatRoom,实现了微信聊天 ...

  5. 上传文件-jq

    var formFile = new FormData(); formFile.append("[file]", fileObj); formFile.append("t ...

  6. Linux服务器中了挖矿木马怎么办?-挖矿木马自助清理手册

    什么是挖矿木马 挖矿木马会占用CPU进行超频运算,从而占用主机大量的CPU资源,严重影响服务器上的其他应用的正常运行.黑客为了得到更多的算力资源,一般都会对全网进行无差别扫描,同时利用SSH爆破和漏洞 ...

  7. 最长公共子序列(LCS)tzoj:5752

    http://www.tzcoder.cn/acmhome/problemdetail.do?method=showdetail&id=5752 题意:求两个串的最长公共子序列(顺序相同即为子 ...

  8. memoのVIM

    必须给今天看到的vim相关的东西记录一下! vim文档中文化 https://github.com/yianwillis/vimcdoc 速查表 https://github.com/skywind3 ...

  9. FFmpeg input与output 函数流程

    重要结构体 AVFormatContext AVCodecContextAVCodecAVPacketAVFrame 0.公共部分 av_register_all(); avfilter_regist ...

  10. ssh反向通信

    ##先决条件为:一个有公网IP的VPS(虚拟主机),我使用的是国内的腾讯云,您也可以选择阿里云,亚马逊等各种厂商产品.这台机器的操作系统为 centos 7.0 ,IP 为 A.A.A.A #双内网主 ...