curl -H "Content-type:application/json" -k https://abx,xyz.com/api/rawquery -d '{"query":"xyz"}
工作,但是使用urllib2获取数据的方法与下面不同。
import urllib
import urllib2
import json
url = "https://abx.xyz.com/api/rawquery"
headers = {"Content-type" :"application/json"}
values = {'query': 'xyz'}
data = urllib.urlencode(values)
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
OUTPUT:
urllib2.HTTPError: HTTP Error 401: Unauthorized