访问印度站点meritindia.in超时,求非VPN解决方案(附Python代码)
访问meritindia.in的非VPN解决方案
问题背景
无法直接访问meritindia.in(印度地区可正常访问),使用免费印度代理的Python请求失败,需求:除VPN外的访问方法。
附原测试代码:
import requests proxies = { 'https': '125.99.106.250:3128' } url = "https://meritindia.in" response = requests.get(url, timeout=30, proxies=proxies) print(response.status_code)
可行解决方案
一、优化代理使用策略
- 验证代理有效性:免费代理稳定性差,先通过命令行验证代理是否可用:
若返回200系列状态码则代理可用,否则更换代理(优先选择付费印度代理,稳定性更高)。curl -x http://125.99.106.250:3128 https://meritindia.in -I - 完善Python请求配置:原代码缺少浏览器UA、代理前缀,部分场景需关闭SSL验证,修改后代码:
import requests proxies = { 'https': 'http://125.99.106.250:3128' # 补充http://前缀,部分代理要求 } # 模拟浏览器请求头 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' } try: # 关闭SSL验证(部分代理证书不合法) response = requests.get("https://meritindia.in", timeout=30, proxies=proxies, headers=headers, verify=False) print(f"状态码:{response.status_code}") print(f"响应内容片段:{response.text[:500]}") except Exception as e: print(f"请求失败原因:{str(e)}") - 使用代理池工具:若坚持用免费代理,可使用代理池自动筛选实时可用的印度代理,避免手动查找的代理失效。
二、使用Tor网络路由
Tor通过全球节点转发请求,可绕过地域限制,步骤:
- 安装Tor服务(Windows/macOS/Linux均可下载官方客户端);
- 修改Python代码使用Tor代理(默认端口9050):
import requests proxies = { 'http': 'socks5://localhost:9050', 'https': 'socks5://localhost:9050' } try: response = requests.get("https://meritindia.in", proxies=proxies, timeout=60) print(f"状态码:{response.status_code}") except Exception as e: print(f"请求失败原因:{str(e)}")
三、搭建反向代理(Cloudflare Workers)
利用Cloudflare Workers搭建中转代理,间接访问目标站点:
- 注册Cloudflare账号,创建新的Workers服务;
- 替换Workers代码为以下内容:
addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) }) async function handleRequest(request) { const url = new URL(request.url) url.hostname = 'meritindia.in' return fetch(url.toString(), request) } - 部署后,访问你的Workers域名即可间接访问meritindia.in。
四、绕过DNS污染
部分地区无法访问是因为DNS解析失败,可尝试:
- 更换公共DNS(如Cloudflare DNS 1.1.1.1、Google DNS 8.8.8.8);
- 在Python中使用DNS-over-HTTPS解析IP后直接访问:
import requests from dns.resolver import Resolver # 使用Cloudflare DoH解析目标域名IP resolver = Resolver() resolver.nameservers = ['1.1.1.1'] ip_records = resolver.resolve('meritindia.in', 'A') target_ip = ip_records[0].address # 直接访问IP,添加Host头标识目标站点 headers = {'Host': 'meritindia.in'} try: response = requests.get(f"https://{target_ip}", headers=headers, verify=False) print(f"状态码:{response.status_code}") except Exception as e: print(f"请求失败原因:{str(e)}")
内容的提问来源于stack exchange,提问作者Mio
相关产品推荐
相关产品推荐

