我目前正在通过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代理。有办法吗?
答案 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)