![](/img/trans.png)
[英]how to use requests.post() with proxy authentication in python?
[英]Why requests.post() does not use a provided proxy in python?
我正在尝试发送带有 http 代理列表的发布请求。 有一段时间我认为代理工作正常,直到我在列表中添加一个假代理以确保一切都像这样工作:
def func_name(i):
url = 'https://www.some-url.com/Cart/ajax/page.php'
# Proxies to connect with
proxies_list = [
'http://1.1.1.1:2000',
'http://2.2.2.2:2000',
'http://1.2.3.0:2000' # This is the fake one
]
proxy_index = random.randint(0, len(proxies_list) - 1)
proxy = {"http": proxies_list[proxy_index]}
# List of user agents
headers_list = [
'Linux Mozilla 5/0',
'Linux Mozilla 5/0',
'Linux Mozilla 5/0'
]
headers_index = random.randint(0, len(headers_list) - 1)
headers = {'user-agent':headers_list[headers_index], 'Accept-Encoding':'none'}
payload = {'dataToValidate':str(i),'actionName':'nc_signup'}
answer = requests.post(url=url, headers=headers, proxies=proxy, data=payload).json()
print(answer)
当proxy_index = random.randint(0, len(proxies_list) - 1)
选择假的我无论如何都会得到答案,原因可能是因为requests.post()
function 甚至不使用参数proxies=proxy
正如预期的那样。
Since you only construct the proxy
object with an http
option, the HTTPS URL you're trying to load is not proxied. 改变
proxy = {"http": proxies_list[proxy_index]}
至
proxy = {"http": proxies_list[proxy_index], "https": proxies_list[proxy_index]}
应该解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.