【问题标题】:Request through proxy Heroku通过代理 Heroku 请求
【发布时间】:2021-01-03 18:35:40
【问题描述】:

当我在 Heroku 上运行这个脚本时,我得到了我的项目 IP 而不是代理。但是如果我在我的电脑上运行它,IP对应代理。

import requests

proxy = { 
              "http"  : http_proxy, 
              "https" : https_proxy,
            }

res = requests.get(url='http://ip.quotaguard.com/')

print(res.content)

为什么会这样?

【问题讨论】:

    标签: python heroku proxy


    【解决方案1】:

    如果要使用代理,还必须在请求中传递参数代理

    (https://docs.python-requests.org/en/latest/)

    所以你的代码会变成:

    import requests
    
    proxy = { 
                  "http"  : http_proxy, 
                  "https" : https_proxy,
                }
    
    res = requests.get(url='http://ip.quotaguard.com/', proxies=proxy)
    
    print(res.content)
    

    【讨论】:

      猜你喜欢
      • 2022-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 2021-03-06
      相关资源
      最近更新 更多