首页 > 解决方案 > 请求库无法解析代理

问题描述

我无法让我的代理工作。

我在想这与 URL 中的破折号有关。不过我不确定。使用普通代理,例如:110.74.222.71:44970它可以工作,但是使用这样的代理我得到:

requests.exceptions.InvalidURL:解析失败:http://174.138.162.202:7383:LV16191381-LV1619137936-116: 35fde12g82

import requests
import random

proxy = {
    'http' : 'http://174.138.162.202:7383:LV16191381-LV1619137936-116:35fde12g82',
    'https' : 'http://174.138.162.202:7383:LV16191381-LV1619137936-116:35fde12g82'
}

headers = {"User Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"}
r = requests.get(url, headers=headers, proxies=proxy)

print(r.status_code)

标签: pythonhttpspython-requests

解决方案


推荐阅读