okex本地正常,但放到国外服务器报错:Access Denied The owner of this website has banned your access based on your browser's signature
故障现象:本地(国内IP)调试正常,放到国外服务器上,程序就报错,Access Denied The owner of this website has banned your access based on your browser's signature
这是在爬虫中一类比较常见的问题,远端服务器为防止各类攻击行为,会对请求做判断。
okex也一样,但可惜的是,okex官方API文档中的说明不够详尽。
官方说明:
![2345截图20171028170615.png][1]
按照官方配置说明,报错依旧。
直接通过国外服务器访问okex的depth页面,正常。
总体来说,是因为headers的问题,于是直接忽略官方文档的提示,将headers改进一下
headers = {
'apisign':sign,
"Content-type" : "application/x-www-form-urlencoded",
'Connection':'keep-alive',
'Cache-Control':'max-age=0',
'Accept': 'text/html, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
'DNT':'1',
'Accept-Language': 'zh-CN,zh;q=0.8,ja;q=0.6',
}
恢复正常。
其实就是骗了一下对方服务器,说我其实是个浏览器。
[1]: http://www.zilly.cn/usr/uploads/2017/10/1770619581.png