李守中

Python 对 requests 包配置代理

Table of Contents

1 全局走 socks5 代理

import requests
import socket
import socks

socks.set_default_proxy(socks.SOCKS5, "192.168.50.101", 10808)
socket.socket = socks.socksocket
resp = requests.get(url="https://ifconfig.me/ip")
text = resp.content.decode('utf-8')
print(text)

2 http 请求走 socks5 代理

import requests

proxies = {
    "http": "socks5://192.168.50.101:10808",
    "https": "socks5://192.168.50.101:10808",
}
resp = requests.get(url="https://httpbin.org/ip", proxies=proxies)
text = resp.content.decode('utf-8')
print(text)


Last Update: 2023-05-18 Thu 09:11

Contact: [email protected]     Generated by: Emacs 27.1 (Org mode 9.3)

若正文中无特殊说明,本站内容遵循: 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议