简体   繁体   English

Python 请求导入代理

[英]Python requests importing proxies

I am trying to create a program to test proxies.我正在尝试创建一个程序来测试代理。 This code should be working but it's not.这段代码应该可以工作,但不是。 I am getting the error "requests.exceptions.InvalidURL: Not supported proxy scheme None"我收到错误“requests.exceptions.InvalidURL:不支持代理方案无”

import requests
from requests.exceptions import Timeout

headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'en-GB,en;q=0.5',
    'DNT': '1',
    'Connection': 'keep-alive',
    'Upgrade-Insecure-Requests': '1',
}

proxy = {
    "http": "169.57.1.85:80",
    "https": "169.57.1.85:80"
}

proxy_Test = requests.get("https://httpbin.org/", headers=headers, proxies=proxy, timeout=10)
print(proxy_Test.status_code)
if proxy_Test.status_code == 200:
    print("this proxy is good:" + str(proxy).replace("{", " ").replace("}", "").replace("'", ""))
else:
    print("This proxy is no good")
try:
    x = requests.get("http://www.google.com", headers=headers, proxies=proxy, timeout=1)
except Timeout:
    print("error found")

try this code试试这个代码

import requests
from requests.exceptions import Timeout


headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'en-GB,en;q=0.5',
    'DNT': '1',
    'Connection': 'keep-alive',
    'Upgrade-Insecure-Requests': '1',
}

proxy = {
    'http':'45.174.70.18:53281',
    'https':'45.174.70.18:53281'
}

proxy_Test = requests.get("https://httpbin.org/", headers=headers, proxies=proxy, timeout=20)
print(proxy_Test.status_code)
if proxy_Test.status_code == 200:
    print("this proxy is good:" + str(proxy).replace("{", " ").replace("}", "").replace("'", ""))
else:
    print("This proxy is no good")
try:
    x = requests.get("http://www.google.com", headers=headers, proxies=proxy, timeout=0.2)
except Timeout:
    print("error found")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM