请求 SSL 连接超时 [英] Requests SSL connection timeout

查看:63
本文介绍了请求 SSL 连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 python 请求向 www.fredmeyer.com 发送 http 请求

I'm using python requests to send http requests to www.fredmeyer.com

我什至无法通过对该域的初始获取请求.做一个简单的 requests.get 会导致连接挂起并且永远不会超时.我已经验证我可以访问这个域并且能够在我的本地机器上运行请求.任何人都可以复制

I can't even get past an initial get request to this domain. doing a simple requests.get results in the connection hanging and never timing out. i've verified i have access to this domain and am able to run the request on my local machine. can anyone replicate

推荐答案

该站点似乎启用了一些过滤以禁止机器人或类似程序.以下 HTTP 请求当前适用于该站点:

The site seems to have some filtering enabled to prohibit bots or similar. The following HTTP request works currently with the site:

GET / HTTP/1.1
Host: www.fredmeyer.com
Connection: keep-alive
Accept: text/html
Accept-Encoding:

如果 Connection 标头被删除或它的值更改为 close,它将挂起.如果(空)Accept-Encoding 标头丢失,它也会挂起.如果 Accept 行丢失,它将返回 403 Forbidden.

If the Connection header is removed or its value changed to close it will hang. If the (empty) Accept-Encoding header is missing it will also hang. If the Accept line is missing it will return 403 Forbidden.

为了通过请求访问此站点,以下当前对我有用:

In order to access this site with requests the following currently works for me:

import requests
headers = { 'Accept':'text/html', 'Accept-Encoding': '', 'User-Agent': None }
resp = requests.get('https://www.fredmeyer.com', headers=headers)
print(resp.text)

请注意,网站用于检测机器人的启发式方法可能会发生变化,因此将来可能会停止工作.

Note that the heuristics used by the site to detect bots might change, so this might stop working in the future.

这篇关于请求 SSL 连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆