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. mysql在windows下安装

    参考博客:https://blog.csdn.net/weixin_43423484/article/details/124408565

  2. Consul 服务注册与发现

    Consul是一种分布式,高度可用且具有数据中心感知能力的解决方案,用于跨动态,分布式基础架构连接和配置应用程序. 1.下载consul.exe 2.在consul.exe文件夹地址栏输入cmd 3. ...

  3. std::string实现split和trim方法

    void split(const std::string& str, const std::string& strDelimiter, std::vector<std::stri ...

  4. C#当窗体大小改变时,窗体中的控件大小也随之改变

    第一种:推荐 在窗体中加上如下代码即可实现,但窗体点击放大按钮时却不能改变控件大小. private Size beforeResizeSize = Size.Empty;protectedoverr ...

  5. java8 stream流的使用

    List<Paper> list = new ArrayList<>();list.add(new Paper("m",2L));list.add(new ...

  6. uni-app使用阿里巴巴图标库icon详细步骤--避免踩坑

    踩了很多坑~~  最终终于找到可以使用阿里图标库的方法  简单方便 阿里巴巴图标库:https://www.iconfont.cn/home/index?spm=a313x.7781069.19989 ...

  7. 使用excel生成多条sql语句

    前提: excel 表里有2列数据,现在要每一列 生成一个sql 语句,应用自定义字符 在第三行单元格里面写入:="zdy"&A2&"zdy"& ...

  8. next.js引入antd报错

    首先在pages根目录下新建一个_app.js   ,代码如下,然后再引入对应antd组件即可 import App from 'next/app' import 'antd/dist/antd.cs ...

  9. developer mode

    PS C:\Windows\system32> reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersio ...

  10. 记录一次echarts 中bar 定时跳跃并显示内容

    查看echarts api -----   https://www.echartsjs.com/zh/api.html#echarts 搜索 1.dispatchAction   执行的关键 2.hi ...