【问题标题】:How do I make proxies work with requests?如何让代理处理请求?
【发布时间】:2021-02-28 13:34:16
【问题描述】:

当我尝试运行我的代码时,我得到一个错误,我不明白为什么。救命!

import requests
import json

proxies = {
  "https": "189.113.217.35:49733",
  "http": "5.252.161.48:8080"
}

r = requests.get("https://groups.roblox.com/v1/groups/1",proxies=proxies)
j = r.json()
print(j)

【问题讨论】:

  • 错误是什么?
  • @Alderven 我想通了,IP 地址无法访问代理。

标签: python python-3.x proxy python-requests


【解决方案1】:

我想通了,IP 地址无法访问代理。

【讨论】:

    【解决方案2】:

    很简单,我会创建一个会话:

    session = requests.Session()

    然后是代理字典:

    代理 = { 'http': 'http://5.252.161.48:8080', 'https': 'http://5.252.161.48:8080' }

    并在会话中注入代理

    session.proxies.update(代理)

    【讨论】:

      猜你喜欢
      • 2012-09-16
      • 1970-01-01
      • 1970-01-01
      • 2020-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      相关资源
      最近更新 更多