我正在尝试编写一个快速脚本,可以使用来自 CloudFlare 的新 1.1.1.1 DNS over HTTPS 公共 DNS 服务器进行 dns 查找。
在这里查看他们的文档https://developers.cloudflare.com/1.1.1.1/dns-over-https/json-format/我不确定我做错了什么以及为什么我收到 415 状态代码(415 不支持的内容类型)。
这是我的脚本: #!/usr/bin/env python import requests import json from pprint import pprint
url = 'https://cloudflare-dns.com/dns-query'
client = requests.session()
json1 = {'name': 'example.com','type': 'A'}
ae = client.get(url, headers = {'Content-Type':'application/dns-json'}, json = json1)
print ae.raise_for_status()
print ae.status_code
print ae.json()
client.close()
Run Code Online (Sandbox Code Playgroud)
这是输出:
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 415 Client Error: Unsupported Media Type for url: https://cloudflare-dns.com/dns-query
Run Code Online (Sandbox Code Playgroud)
对于 json 响应(我相信):
raise ValueError("No JSON object could be decoded") …Run Code Online (Sandbox Code Playgroud)