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. R6-1 数字金字塔

    1 void pyramid(int n) 2 { 3 int i, j; 4 5 for(i = 0;i < n;i++){ 6 for(j = 0;j < n - i - 1;j++) ...

  2. 【Python】开始学习叭

    学习视频:https://www.bilibili.com/video/BV1wD4y1o7AS    

  3. 打包exe

    2.要打包的文件为多个py文件 这种情况一般你的代码较多,项目较大,可能你写了一个GUI界面py文件这个文件调用了其他文件的函数什么的,这个时候你需要生成spec文件来打包,这里假设你的要打包的主文件 ...

  4. react backend and frontend download file

    import {  View as ViewFile} from '@/api/SafetyRule'; const Handler_DownLoadFile = (Id:number,IsEngli ...

  5. Github快速访问

    Github快速访问 1. 国内访问github慢     github是国外网站,用国内的网络很难访问到,也就无法使用github,作为程序猿的我们,无法使用github可太难受了,那么我们有什么办 ...

  6. leecode62不同路径(动态规划)

    一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 "Start" ). 机器人每次只能向下或者向右移动一步.机器人试图达到网格的右下角(在下图中标记为 &quo ...

  7. 最简单明了的yield from解释

    def one(): print('one start') res = yield from two() print('function get res: ', res) return 'one' + ...

  8. How to find WWN and WWPN of HBA card in Linux

    There are several ways to detect the WWN of a Fibre Channel (FC) HBA and their details in Linux/Unix ...

  9. 使用Latex错误集

    1.写公式的函数--align(最怕空行) (1)align用法示例 \begin{align} & \left\{ \begin{array}{ll} \sup\limits_{\tilde ...

  10. 随机生成四则运算表达式【Unity】

    根据自己项目需求调整代码中表达式的公共方法 using System.Collections; using System.Collections.Generic; using System; usin ...