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. [CSP-S2019] Emiya 家今天的饭

    洛咕 题意:原题面见链接,简单来说就是给出一个\(n*m\)的矩阵,每一行代表同一种烹饪方法,每一列代表同一种食材,\(a_{i,j}\)表示使用第i种烹饪方法第j种食材能做出多少种菜,要求至少做一道 ...

  2. 配置PostMan以访问、连接D365 / Dataverse环境

    有人提出个问题说国内21V环境能否使用postman连接CRM? 官方链接:https://learn.microsoft.com/en-us/power-apps/developer/data-pl ...

  3. 权昌TSC244条码打印机如何加载数据实现大批量打印呢?

    我公司的TSC TTP-244条码打印机,只会改个名称打一张,怎么样改数据或者是加载数据实现大量打印的呢?   解答:   TSC TTP-244条码打印机,是一款性能不错的桌面型条码打印机,最大打印 ...

  4. git 与远程仓库关联返回 fatal: remote origin already exists 解决方法

    今天领导新建了一个代码仓库,我按照流程一步步推送代码,结果到了关联仓库的时候,返回 fatal: remote origin already exists(远程源已经存在) 下面是解决方法 1.删除远 ...

  5. Zero-Shot Temporal Action Detection via Vision-Language Prompting概述

    1.针对的问题 现有的方法在推断时只能识别之前见过的类别,即训练时出现过的类别,而为每个感兴趣的类收集和注释大型训练集是昂贵的. 2.主要贡献 (1)研究了如何利用大量预训练的ViL模型进行未修剪视频 ...

  6. docker容器生命周期管理

    查看容器版本 docker version [root@node1 ~]# docker version Client: Docker Engine - Community Version: 20.1 ...

  7. unity创建一个数组,让他随机生成一个东西之C#语言(有图教程)

    using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; ...

  8. leetcode 98. 验证二叉搜索树 【一遍dfs】【时间击败99.72%】【内存击败94.23%】

    复用left[],[时间击败73.33%]-->[时间击败99.72%] [内存击败36.17%]-->[内存击败94.23%] dfs(r)返回值=new long[]{包括r节点的子树 ...

  9. mysql8.0修改密码

    把密码设置为空:UPDATE mysql.user SET authentication_string='' WHERE user='root' and host='localhost'; 查看USE ...

  10. QDateEdit

    self.dateEdit.setCalendarPopup(True) # 日历增加 # 日历转化位str类型begintime = self.dateEdit.dateTime().toStrin ...