Python里面requests.post请求怎么添加代理

Python里面requests.post请求怎么添加代理,第1张

下面是官方文档中的介绍,post和get方式相同,都是加proxies=proxies这个参数 即可,下面是官方文档内容。

Proxies

If you need to use a proxy, you can configure individual requests with the

proxies argument to any request method:

import requests

proxies = {

'http': 'http://10.10.1.10:3128',

'https': 'http://10.10.1.10:1080',

}

requests.get('http://example.org', proxies=proxies)

You can also configure proxies by setting the environment variables

HTTP_PROXY and HTTPS_PROXY.

$ export HTTP_PROXY="http://10.10.1.10:3128"

$ export HTTPS_PROXY="http://10.10.1.10:1080"

$ python

>>>import requests

>>>requests.get('http://example.org')

To use HTTP Basic Auth with your proxy, use the http://user:password@host/ syntax:

proxies = {'http': 'http://user:pass@10.10.1.10:3128/'}

To give a proxy for a specific scheme and host, use the

scheme://hostname form for the key. This will match for

any request to the given scheme and exact hostname.

proxies = {'http://10.20.1.128': 'http://10.10.1.10:5323'}

Note that proxy URLs must include the scheme.

下面是我之前做过的 Get 请求时用的,代理的代码,是可行

var req = WebRequest.Create(url) as HttpWebRequest

// 设置代理

var /w/e/b/P/r/o/x/y = new /W/e/b/P/r/o/x/y(代理 Ip, 代理端口)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/7894942.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存