安装 pysocks:pip install pysocks
# coding:utf-8
'''
@version: python3.6
@license: Apache Licence
@software: PyCharm
@file: pysocks.py
@time: 2022/3/25 16:27
'''
import socket
import requests
import socks
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9311)
socket.socket = socks.socksocket
def main():
url = 'https://api.ip.sb/ip'
html = requests.get(url).text
print(html)
if __name__ == '__main__':
main()
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
import socket
import socks
SOCKS5_PROXY_HOST = 'xxxx' # socks 代理IP地址
SOCKS5_PROXY_PORT = xxx # socks 代理本地端口
default_socket = socket.socket
socks.set_default_proxy(socks.SOCKS5, SOCKS5_PROXY_HOST, SOCKS5_PROXY_PORT)
socket.socket = socks.socksocket
session = requests.session()
session.keep_alive = False
res=session.get("http://ipconfig.cc/",timeout=5)
print(res.text)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。