【发布时间】:2019-05-31 00:52:46
【问题描述】:
我正在尝试通过代理服务器向此 URL https://verify-email.org/home/verify-as-guest/example@example.com 发送请求。
我在这里获得了代理服务器: https://free-proxy-list.net/
verify-email 网站限制每小时免费验证 5 封电子邮件。
当我使用代理服务器时,如果我不断更改代理服务器,我可以绕过此限制。这在我使用 curl 时有效:
curl --proxy http://IP:PORT https://verify-email.org/home/verify-as-guest/example@example.com
上述命令完美运行。
但是当我在 python 中做同样的事情时:
import requests
from pprint import pprint
def check_email(email):
proxyDict = {
"http" : 'http://IP:PORT'
}
result = requests.get('https://verify-email.org/home/verify-as-guest/' + email, proxies=proxyDict, timeout=5).json()
pprint(result)
check_email('example@example.com')
它不起作用。它只是给了我 5 次尝试然后停止工作,即使我更改了 IP,这让我相信 curl 发送的请求和 requests 发送的请求存在差异。
有什么方法可以在 python-requests 中获得相同的“curl”请求?
【问题讨论】:
-
为服务付费...‽ 价格相当实惠。
-
@deceze 其实我不介意付钱。我只是想弄清楚为什么请求库不起作用。
-
即使是上面的问题,我也可以想出一个变通的办法,写一个使用curl的shell脚本,在Python脚本中调用,或者直接用subprocess调用curl。但我试图理解为什么请求不同。我尝试拦截使用 netcat 生成的请求:这是带有 curl 的请求:GET / HTTP/1.1 Host: my host User-Agent: curl/7.54.0 Accept: /这是带有请求的那个: GET / HTTP/1.1 Host: * my host * User-Agent: python-requests/2.13.0 Accept-Encoding: gzip, deflate Accept: /
标签: python curl proxy python-requests