簡體   English   中英

為什么 requests.post() 不使用 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM