Saturday, 15 May 2010

python - urllib2 gives 401 while curl works (without auth) -



python - urllib2 gives 401 while curl works (without auth) -

curl -h "content-type:application/json" -k https://abx,xyz.com/api/rawquery -d '{"query":"xyz"}

works, fetching info urllib2 not below.

import urllib import urllib2 import json url = "https://abx.xyz.com/api/rawquery" headers = {"content-type" :"application/json"} values = {'query': 'xyz'} info = urllib.urlencode(values) req = urllib2.request(url, data, headers) response = urllib2.urlopen(req) output: urllib2.httperror: http error 401: unauthorized

python urllib2

No comments:

Post a Comment