如何判断Python中的GET请求是使用https还是http代理?

时间:2018-09-05 06:28:23

标签: proxy python-requests tor

我目前正在通过Python3中的requests库在发出获取请求时使用代理。我为代理设置了Tor和Privoxy,代码如下:

import requests
proxies = {
    "http": "http://127.0.0.1:8118",
    "https": "https://127.0.0.1:8118"
}
resp = requests.get("https://icanhazip.com", proxies=proxies)

我想知道是否有一种方法可以查看resp中是否使用了HTTP或https代理。有办法吗?

1 个答案:

答案 0 :(得分:2)

我认为最Python化的方式是这样的:

describe('context level 1', () => {
  describe('context level 2', () => {
    before(() => {
      doSomeSetup();
    });

    it('test case 1', () => {
      try {
        const a = await subject();
        should(result).balahalah();
      } catch (e) {
        should.not.exist(e);
      }
    });
  });

  describe('context level 2', () => {
    before(() => {
      doSomeSetup();
    });

    it('test case 2', () => {
      try {
        const a = await subject();
        should.not.exist(a);
      } catch (e) {
        e.message.should.equal('xxxdasfsda');
      }
    });
  });
});

或者,您可以执行以下操作:

import requests
from urllib.parse import urlparse

def get_scheme(url):
    return urlparse(url).scheme

url = 'https://www.whatever.com'
response = requests.get(url)

scheme = get_scheme(response.url)