Python请求JSON文件返回None

时间:2017-08-15 00:08:13

标签: python json python-2.7 python-requests

from fake_useragent import UserAgent
import requests

ua = UserAgent()
header = {'User-Agent':str(ua.chrome)}

d = {"query": "/api/v2/details/ip/", "query_entry": "41.219.127.69"}


r = requests.get("https://talosintelligence.com/sb_api/query_lookup/", 
data = d, headers=header)

当我从主站点" talosintelligence.com"运行相同的结果时并查看网络顾问,确切的URL是使用JSON文件响应的,但来自python的get请求返回None

Screenshot of page

1 个答案:

答案 0 :(得分:1)

我通过设置referer标题来实现它。

import requests
sess = requests.session()
ip_addr = "41.219.127.69"
ret = sess.get('https://talosintelligence.com/sb_api/query_lookup', data={"query": "/api/v2/details/ip/", "query_entry": ip_addr, "offset": 0, "order": "ip asc"}, headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.31 Safari/537.36', 'referer': 'https://talosintelligence.com/reputation_center/lookup?search=' + ip_addr})