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. fix: because the volume group on the selected device also consist of physical volumes on other devices

    because the volume group on the selected device also consist of physical volumes on other devices 目标 ...

  2. sap IUT255 Integration of SAP CRM and SAP IS-U_EN_Col62.pdf

    sap IUT255 Integration of SAP CRM and SAP IS-U_EN_Col62.pdf   sap IUT255 Integration of SAP CRM and ...

  3. C#中的ReferenceEquals、Equals以及==

    https://www.cnblogs.com/ArtofDesign/p/3615212.html   C#中有一共有四种相等性判断方法: //Object中定义的三个方法 public stati ...

  4. css动画-滚动通知

    使用动画 <div class="horNotice"> <div class="horMove"> <span>累计87例 ...

  5. JDK8的异步处理方式-CompletableFuture的使用

    一.背景 jdk8中加入了实现类CompletableFuture,用于异步编程.底层做任务使用的是ForkJoin, 顾名思义,是将任务的数据集分为多个子数据集,而每个子集,都可以由独立的子任务来处 ...

  6. Safari浏览器如何收藏网页?

    Safari浏览器是MacOS所自带的一款功能强劲的浏览器,许多MacOS的用户在使用过Safari浏览器后就不会去下载其他浏览器了.对于很多Mac新手用户来说,如何使用Safari浏览器来收藏喜欢的 ...

  7. 学习lua-01,遍历集合,多入参循环处理,类型判断,数字运算

    --function maxnum(tab1) -- local b = 1 -- local a = tab1[b] -- for i, v in ipairs(tab1) do -- if v & ...

  8. holiday09

    第九天 ping # 检测目标主机是否连接正常 $ ping IP地址 # 检测本地网卡工作正常 $ ping 127.0.0.1 ping 一般用于检测当前计算机到目标计算机之间的网络 是否通畅,数 ...

  9. adb查看包名

    方法一:adb shell pm list packages 方法二:adb shell dumpsys activity activities (前提条件:手机应用上只启动你要用的APP) 方法三: ...

  10. web执行sql----vue mybatis

    java @ResponseBody @RequestMapping(value = "/sqlMap", method = RequestMethod.POST) public ...