【问题标题】:Can't figure out how to test proxy with Soundcloud API无法弄清楚如何使用 Soundcloud API 测试代理
【发布时间】:2014-09-07 03:17:45
【问题描述】:

我正在尝试将我的代理与 Soundcloud API 一起使用。格式是

client = soundcloud.Client(client_id=client_id,
                           client_secret=client_secret,
                           username=username,
                           password=password,
                           proxies=proxies)

但是,当我将某些内容传递给代理变量时,例如

proxies = {'http': 'notavalidip'}

客户端仍然能够登录并正常运行。为什么会发生这种情况,我如何测试当我通过一个实际有效的代理时它会被实际使用?我相信这个 API 使用 Python requests 库,如果有帮助的话。

【问题讨论】:

    标签: proxy soundcloud python-requests


    【解决方案1】:

    所有这些选项都传递给make_request,最终被传递到request_func 内的kwargs,这确实得到了requests 库的支持。

    您的代理通过只是因为它的方案错误。所有与 Soundcloud 的连接都是通过 https 而非 http by default 进行的。这意味着您没有设置代理,因为您的代理字典没有 https 键。

    请参阅 here 代理如何简单地设置为 None,因为字典没有所需的方案。

    在将您的 proxies 变量修改为 https 而不是 http 后,我抛出了一个异常 (ProxyError('Cannot connect to proxy.'),所以没有静默失败。

    希望这是有道理的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-03
      • 2014-12-18
      • 2013-04-10
      相关资源
      最近更新 更多