ITPub博客

首页 > 应用开发 > Python > Python requests设置代理的方法

Python requests设置代理的方法

Python 作者:安全剑客 时间:2020-03-03 10:03:59 0 删除 编辑
这篇文章主要介绍了Python requests设置代理的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,
指导文档:

http://docs.python-requests.org/en/master/user/advanced/ 的Proxies
http://docs.python-requests.org/en/latest/user/advanced/ 的SSL Cert Verification

requests设置代理
import requests
proxies = {'http': 'http://localhost:8888', 'https': 'http://localhost:8888'}
url = 'http://www.baidu.com'
requests.post(url, proxies=proxies, verify=False) #verify是否验证服务器的SSL证书
执行结果:

Python requests设置代理的方法Python requests设置代理的方法

基于 selenium的代理设置:
from selenium import webdriver
proxy='124.243.226.18:8888' 
option=webdriver.ChromeOptions()
option.add_argument('--proxy-server=http://'+proxy)
driver = webdriver.Chrome(options=option)
driver.get('http://httpbin.org/get')
python3.8 request proxy(代理)失效解决方案

在使用python3.8版本的时候,我们使用request库的时候,可能会遇到
Python requests设置代理的方法Python requests设置代理的方法
下面这样的错误,这是游戏底层修改了url解析模式,导致proxy代理解析失败导致的。
解决方案是:
如果不使用代理,那么就可以改成

proxies = {
"http": "",
"https": "",
}
request.get(url,proxies=proxies)

如果使用代理的话,就可以修改成:

proxies = {
"http":" http://127.0.0.1:1080", 
"https":"https://127.0.0.1:1080", 
}
需要注意:

一定要写成http://+ip+port这种形式,不能去掉前面的http://,否则就会产生错误。
到此这篇关于Python requests设置代理的方法步骤的文章就介绍到这了,

原文地址: https://www.linuxprobe.com/requests-howto-setupaproxy.html

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31559985/viewspace-2678186/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2018-11-01

  • 博文量
    1407
  • 访问量
    1395863